Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTime from CFDirectory not being interpreted correctly by ColdFusion

We have Coldfusion installed on Windows Server 2003

A dump of CFDirectory on the undelivered mail returns the following:

enter image description here

But the problem is upon iterating this query, when I dump the date with:

#dateFormat(mailStubs.DateLastModified,'dd-mmm-yyyy')#

This is what I get:

11-Nov-2026
11-Nov-2027
11-Nov-2028
11-Nov-2029
11-Nov-2029
11-Nov-2029
11-Nov-1930
11-Nov-1930
11-Nov-1930
11-Nov-1930
11-Nov-1930
11-Nov-1930
11-Nov-1930
11-Nov-1930

So doing:

datediff("n", mailStubs.DateLastModified, now())

now() being 30th Nov 2011 lets say 2:00 PM gives me very weird results

This only happens on Windows server 2003 (Our production server), it worked fine on my local system (XP)

Any ideas?

like image 589
Charlie Brown Avatar asked Oct 21 '25 07:10

Charlie Brown


1 Answers

I know this is a really old thread, but ... cfdirectory returns a localized date string (not date object). So you should be using the LS (locale sensitive) date functions to parse it. The reason is that the standard CF date functions (DateFormat, ParseDateTime, ...) always use U.S. date conventions. Since the U.S. convention is month first, you will get the wrong results if you pass in a "dd-mm-yyyyy" date string. (At least some of the time.)

<cfscript>
   setLocale("en_GB");
   WriteOutput( dateFormat(lsParseDateTime("26/11/11 2:42 PM"), "dd-mmm-yyyy") );
</cfscript>
like image 118
Leigh Avatar answered Oct 24 '25 02:10

Leigh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!