Copy link to clipboard
Copied
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?
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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".
Copy link to clipboard
Copied
Cynic
😉
--
Adam
Copy link to clipboard
Copied
Glad you agree Adam
Copy link to clipboard
Copied
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 😉