Skip to main content
Participant
March 15, 2011
Question

Date Time in Coldfusion at Daylight Saving

  • March 15, 2011
  • 2 replies
  • 1550 views

Hi

In coldfusion, I have problem creating Date Time using CreateDateTime when the daylight saving switch. For example

CreateDateTime(2011,3,13,2,0,0) gives error.

Also if you do like this

DateAdd('h',1,CreateDateTime(2011,3,13,1,0,0)) gives "2011,3,13,3,0,0" ie instead of 2AM it returns 3AM. This is happening every daylight saving switch time.

This is a bug in coldfusion?

It should be fixed by Coldfusion.

Thanks

    This topic has been closed for replies.

    2 replies

    Inspiring
    March 15, 2011

    I suspect this is not a bug in CF, it's a bug in your understanding of daylight saving.

    If you are in a TZ that commences DLS @ 2am, 13/3/yyyy - like the United States, for example - then there is no such thing as 2am, that day.  Adding 1h to 1am should indeed yield 3am.  This is the whole nature of day light saving: at the "juncture" time, time skips forward one hour.  The moment it strikes 2am, time skips forward to 3am.

    --

    Adam

    Participant
    March 16, 2011

    When we loop through the 24 hours on daylight saving day e.g

    <cfset startDate = CreateDateTime(2011,3,13,0,0,0)>

    <cfoutput>

    <cfloop from="1" to="22" index="dayNo">

         <cfset startDate = dateAdd('h', 1, startDate)>

         #hour(startDate)#<br>

    </cfloop>

    </cfoutput>

    This will show wrong hours (2 is missing)

    1
    3
    4
    5
    6
    7
    8
    9

    Inspiring
    March 16, 2011

    Did you read my post?  The one you are replying to, I mean.

    There is no 2am on the day that DLS starts.  The minute after 01h59 is 03h00.  There is no 02h00.  or any time between 02h00 and 02h59.

    Your code is correct.

    It's your expectations that are off.

    --
    Adam

    Inspiring
    March 15, 2011

    Do the datetimes you are trying to create exist in your timezone?  They don't in mine.