Remove last 5 characters in string - ColdFusion

242 Views Asked by At

I am trying to clean up my Date/TimeStamp before I show it to the user on the page.

I am pulling the following information from a database MSSQL and it is stored in the myDate variable:

#myDate#  =   2015-06-10 11:47:00.0

What I would like to do is cleanup myDate so that is looks like this:

2015-06-10 11:47

I have explored using Left but I believe that only works for strings.

I am not 100% sure how this is accomplished in ColdFusion.

Thanks let me know if more information is needed.

1

There are 1 best solutions below

0
On

If you are using CF9 or below, you can use dateFormat() and timeFormat() functions to accomplish it. Like this.

<cfoutput>
     #DateFormat(mydate, "yyyy-mm-dd")# #TimeFormat(mydate, "hh:mm")#
</cfoutput>

In case you want to display time in 24 hour format you can use HH as mask in timeFormat() function. For more details go through these links:

If you are using CF10 or above then, as @Leigh suggested, you can use dateTimeFormat() function. Like this.

<cfoutput>
    #DateTimeFormat(mydate, "yyyy-mm-dd hh:nn")#
</cfoutput>

Where nn is the mask for displaying minutes. For more options go through the link @Leigh suggested.