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

Weird Issue with DateFormat

Guest
Feb 05, 2010 Feb 05, 2010

Has anyone encountered this issue before,

<cfset strDateTime = DateFormat(DateAdd( "s", GetTimeZoneInfo().UTCTotalOffset, Now()),"yyyy-mm-dd HH:mm:ss")>

<cfset TestDate = DateAdd( "s", GetTimeZoneInfo().UTCTotalOffset, Now())>

Output

=============================================

Date1 = {ts '2010-02-05 22:21:54'}
Date2 = 2010-02-05 22:02:54

How come the output for minutes stays the same on #strDateTime# everytime i run it?

427
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 ,
Feb 05, 2010 Feb 05, 2010

"yyyy-mm-dd HH:mm:ss")>

The DateFormat() masks do not have a "minutes" portion. So the "m" is actually returning the month not minutes. You have to use DateFormat() + TimeFormat().

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
Feb 05, 2010 Feb 05, 2010

Thanks you all for your help, that was exactly the problem, now its fixed!!!

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 ,
Feb 05, 2010 Feb 05, 2010

Because DATEformat() is for formatting dates, not times.  "mm" as far as dateFormat() is concerned means "month".

You need to use TIMEformat() to format times.

--

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 ,
Feb 05, 2010 Feb 05, 2010
LATEST

A lot of people make this mistake because DateFormat() confusingly allows the hours and seconds portions. But yes, DateFormat really does not format times. So as mentioned, you have to use two separate functions to handle the date and time.

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