Leeish
Leeish

Reputation: 5213

Why does ColdFusion Format Dates Differently using the same function

Consider the following code:

<cfset lateDate = createDate(2014,12,8) />
<cfset currentdate = createDate(2015,4,15) />
<cfdump var="#lateDate#" />
<cfdump var="#currentdate#" />
<cfdump var="#dateCompare(currentdate,lateDate)#" />

Output on my machine is: {ts '2014-12-08 00:00:00'} {ts '2015-04-15 00:00:00'} 1

Question 1: Why is the month switched on the two dates. (month/day). The spec says create date is yyyy,mm,dd and yet either CF switched them or it's displaying them switched.

It's doing the dateCompare correctly so what is going on. Have I been staring at this too long?

Upvotes: 2

Views: 59

Answers (1)

Miguel-F
Miguel-F

Reputation: 13548

I think you have been looking at it too long. Both of those are valid dates and the month is not being switched. One of your dates is April 15, 2015 and the other is December 8, 2014. I assume you were thinking August 12, 2014 for that date. Then your code should be createDate(2014,8,12). Right?

The dateCompare function only tells you if the first date is earlier or later than the second date. For both of your dates, the correct one and your assumed one, the first date is later than the second.

I think the code is working correctly. As in:

createDate(2014,8,12) <!--- August 12, 2014  --->
createDate(2014,12,8) <!--- December 8, 2014 --->
createDate(2015,4,15) <!--- April 15, 2015   --->

dateCompare "April 15, 2015" "December 8, 2014" returns 1

dateCompare "April 15, 2015" "August 12, 2014" returns 1

Upvotes: 7

Related Questions