Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Dateformat vs Timeformat off by 1 minute = bug?

Guest
Jan 18, 2010 Jan 18, 2010

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?

938
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 18, 2010 Jan 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
  • ...
    Translate
    LEGEND ,
    Jan 18, 2010 Jan 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.
  • Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    Guest
    Jan 18, 2010 Jan 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

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    Guide ,
    Jan 18, 2010 Jan 18, 2010

    Exactly.

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

    "mm" refers to months, therefore you're actually showing January as your minutes.

    Dateformat isn't meant to be doing times, don't really know why hour and second work but they do, probably due to the underlying java classes it's calling.

    Annoying that they don't have a dateTimeFormat(), but you can always create your own.

    O.

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    Valorous Hero ,
    Jan 19, 2010 Jan 19, 2010

    don't really know

    why hour and second work but they do

    I do not think anyone does. But supposedly the feature was left in for compatibility reasons.

    http://www.bennadel.com/blog/825-Hours-And-Seconds-Work-In-ColdFusion-DateFormat-.htm

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    Guide ,
    Jan 19, 2010 Jan 19, 2010

    Heh. So basically:

    Adobe: "Aaaah craaap. Forgot to stop those other bits of dateformat working before the rollout"

              "Say it's for compatibility reasons?"

              "Good plan."

              "LUNCH".

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    LEGEND ,
    Jan 19, 2010 Jan 19, 2010

    Cynic

    😉

    --

    Adam

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    Guide ,
    Jan 19, 2010 Jan 19, 2010

    Glad you agree Adam

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    Valorous Hero ,
    Jan 19, 2010 Jan 19, 2010
    LATEST
    Forgot to stop those other bits of dateformat working before the rollout"

              "Say it's for compatibility reasons?"

              "Good plan."

              "LUNCH".

    Nah, I could believe the original inclusion was a mistake ... but that it was deliberately left in later.  I am not nearly that cynical 😉

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    Resources