Question

When I retrived a Date field in TOAD it displayed like is '1/18/2038 9:14:07 PM',

But when I rertrived in Coldfusion using cfquery and displayed using , then I got the date on screen like '2038-01-18 21:14:07.0'.

Does anyone have idea why it displayed in different format? Is there anyway we can make it display like TOAD format?

I am using Oracle 10g DB and coldfusion 8

Was it helpful?

Solution

You could use something like:

<cfquery datasource="northwind" name="queryDB">
  SELECT date_used, time_used
  FROM invoicesTable
</cfquery>

<cfoutput query="queryDB">
#DateFormat(date_used, "m/d/yyyy")#
#TimeFormat(time_used, "h:mm tt")#
</cfoutput>

I think this is what you want.

You could use

#DateTimeFormat(Now(), "mmm d, yyyy","h:mm TT")#

to have datetime format

Happy coding

OTHER TIPS

The Coldfusion datetime variable you retrieved from your database has all the information you are requesting. Coldfusion will automatically convert it to a variety of outputs depending on your need using some built in functions.

<!--- Assuming that 'myDateTime' is a datetime variable retrieved from cfquery --->
<cfoutput>
    <!--- Outputs: 1/7/2010 --->
    #dateFormat(myDateTime, "m/d/yyyy")#
    <!--- or use a mask shortcut - only outputs two digit year: 1/7/10 --->
    #DateFormat(myDateTime, "short")#

    <!--- Outputs: 8:47:14 AM --->
    #timeFormat(myDateTime, "h:mm:ss tt")#
    <!--- or use the shortcut: --->
    #TimeFormat(myDateTime, "medium")#
</cfoutput>

If you must construct a single string with the TOAD format, then you may concatenate the output of the dateFormat() and timeFormat() strings.

<!--- Outputs: '1/7/2010 8:47:14 AM' --->
<cfset toadFormat = dateFormat(myDateTime, "m/d/yyyy") & " " & TimeFormat(myDateTime, "medium")>

This saves a bit of hassle if you'll be using this data many times. However for most needs this is unnecessary as the original myDateTime variable contains all the information needed for all purposes other than display output.

More about DateFormat() and TimeFormat() from Adobe. More about DateFormat and TimeFormat shortcuts from Pete Freitag.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top