Michael
Michael

Reputation: 1607

Railo DateFormat gives bad result?

I'm migrating files from Coldfusion 10 to Railo(using Railo Express). I spotted a strange behavior with the DateFormat function. Running the following code:

<cfoutput>
  #Dateformat(now(),'yyyy-mm-dd hh:mm:ss')#
</cfoutput>

In Coldfusion, I get:

2014-12-09 01:12:29

which is good.

In railo, I get:

2014-12-09 hh:12:ss

I don't understand what's going on.

Upvotes: 0

Views: 136

Answers (1)

Adam Cameron
Adam Cameron

Reputation: 29870

Just so there's a proper answer to this (da_didi and Leigh have both put important info in comments, but not as answers):

In both Railo and ColdFusion dateFormat() only formats dates. IE: not the time components.

What you need is dateTimeFormat():

<cfoutput>
    #dateTimeformat(now(),'yyyy-mm-dd hh:nn:ss')#
</cfoutput>

Also note that the mask character for minutes is not m but n (to disambiguate minutes from months).

You also probably want to use HH for hours, otherwise you have an ambiguity between AM and PM times. Or you could suffix the time part with tt. Using HH is closer to standards though, so is probably preferable.

Upvotes: 4

Related Questions