Skip to main content
February 5, 2010
Question

Weird Issue with DateFormat

  • February 5, 2010
  • 2 replies
  • 450 views

Has anyone encountered this issue before,

<cfset strDateTime = DateFormat(DateAdd( "s", GetTimeZoneInfo().UTCTotalOffset, Now()),"yyyy-mm-dd HH:mm:ss")>

<cfset TestDate = DateAdd( "s", GetTimeZoneInfo().UTCTotalOffset, Now())>

Output

=============================================

Date1 = {ts '2010-02-05 22:21:54'}
Date2 = 2010-02-05 22:02:54

How come the output for minutes stays the same on #strDateTime# everytime i run it?

    This topic has been closed for replies.

    2 replies

    Inspiring
    February 5, 2010

    Because DATEformat() is for formatting dates, not times.  "mm" as far as dateFormat() is concerned means "month".

    You need to use TIMEformat() to format times.

    --

    Adam

    Inspiring
    February 5, 2010

    A lot of people make this mistake because DateFormat() confusingly allows the hours and seconds portions. But yes, DateFormat really does not format times. So as mentioned, you have to use two separate functions to handle the date and time.

    Inspiring
    February 5, 2010

    "yyyy-mm-dd HH:mm:ss")>

    The DateFormat() masks do not have a "minutes" portion. So the "m" is actually returning the month not minutes. You have to use DateFormat() + TimeFormat().

    February 5, 2010

    Thanks you all for your help, that was exactly the problem, now its fixed!!!