Skip to main content
January 18, 2010
Answered

Dateformat vs Timeformat off by 1 minute = bug?

  • January 18, 2010
  • 1 reply
  • 1142 views

Can anyone confirm they are seeing this and if so is it a bug or a feature

<cfset mydate = "01/17/2010 12:00:05 AM">
<cfset newdate = dateadd("h", -7, mydate)>


#dateformat(newdate,"mm/dd/yyyy hh:mm:ss")#

#DateFormat(newdate, "mm/dd/yyyy")# #TimeFormat(newdate, "hh:mm:ss tt")#

returns

01/16/2010 05:01:05
01/16/2010 05:00:05 PM


Why the time difference of 1 minute?

    This topic has been closed for replies.
    Correct answer Dan_Bracuk

    When I do this:

    <cfset mydate = "01/17/2010 12:00:05 AM">
    <cfset newdate = dateadd("h", -7, mydate)>

    <cfoutput>
    #newdate#
    <br />
    #dateformat(newdate,"mm/dd/yyyy hh:mm:ss")#
    <br />
    #DateFormat(newdate, "mm/dd/yyyy")# #TimeFormat(newdate, "hh:mm:ss tt")#
    </cfoutput>

    I get this:

    {ts '2010-01-16 17:00:05'}
    01/16/2010 05:01:05
    01/16/2010 05:00:05 PM

    If I use this

    <cfset newdate = CreateDateTime(2010,1,17,0,0,5)>

    I get the same results.

    When I read the docs, I see this for dateformat

  • mm: Month as digits; leading zero for single-digit months.
  • 1 reply

    Dan_BracukCorrect answer
    Inspiring
    January 18, 2010

    When I do this:

    <cfset mydate = "01/17/2010 12:00:05 AM">
    <cfset newdate = dateadd("h", -7, mydate)>

    <cfoutput>
    #newdate#
    <br />
    #dateformat(newdate,"mm/dd/yyyy hh:mm:ss")#
    <br />
    #DateFormat(newdate, "mm/dd/yyyy")# #TimeFormat(newdate, "hh:mm:ss tt")#
    </cfoutput>

    I get this:

    {ts '2010-01-16 17:00:05'}
    01/16/2010 05:01:05
    01/16/2010 05:00:05 PM

    If I use this

    <cfset newdate = CreateDateTime(2010,1,17,0,0,5)>

    I get the same results.

    When I read the docs, I see this for dateformat

  • mm: Month as digits; leading zero for single-digit months.
  • January 18, 2010

    ahhhh... and yes if you change the month to 05 you get 05:05:05

    so mm is interpreted as month which is fine but maybe it shouldn't do anything for ss then? seems like it is addressing 1/2 the timeformat (ss) and not the min so why have it work at all?

    so really...it's not a bug...it's a feature