SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict capescafe's Avatar
    Join Date
    Dec 2004
    Location
    Bellevue, WA
    Posts
    222
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Calendar gives error only for month of February??

    Here is the cf code causing the problem in the error msg:
    Code:
    <cfif IsDefined("url.month")>
      	<cfset tNow = CreateDateTime(#url.year#, #url.month#, #day(now())#, 00,00,00)>
      <cfelseif IsDefined("form.month")>
    	<cfset tNow = CreateDateTime(#form.year#, #form.month#, #day(now())#, 00,00,00)>
      <cfelse>
      	<cfset tNow = Now()>
      </cfif>
    Here is the error msg I get on my calendar page when I choose the month of February (all other months work ok):


    Error Diagnostic Information

    An error occurred while evaluating the expression:

    tNow = CreateDateTime(#form.year#, #form.month#, #day(now())#, 00,00,00)

    Error near line 7, column 8.

    In the function CreateDateTime(year, month, day, hour, minute, second) the combination of the arguments, which are 2010- 2-30 0: 0: 0, have resulted in an invalid date value. The valid range of dates approximately covers the period between 100 AD and 9999 AD

    The error occurred while processing an element with a general identifier of (CFSET), occupying document position (7:2) to (7:81).
    Not sure if I need to give more code here or not. Can anyone see anything to correct this?
    Carolyn (cape's cafe)
    Twitter | My Treehouse Profile | eBookFling

  2. #2
    SitePoint Evangelist
    Join Date
    Mar 2007
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    which are 2010- 2-30 0: 0: 0, have resulted in an invalid date value.
    The month of February doesn't have 30 days ... ever

    CreateDateTime(#form.year#, #form.month#, #day(now())#, 00,00,00)
    #day(now())# won't work in a few cases. Not just february. If you want the last day of the month, determine the first of the month. Then use it to calculate the last day of the month with date functions. In psuedo code, somethin like

    <cfset firstOfMonth = createDate(someYear, someMonth, 1)>
    <cfset lastOfMonth = dateAdd("d", DaysInMonth(firstOfMonth)-1, firstOfMonth)>


    BTW: If you don't need a time. Just use createDate() instead of CreateDateTime()

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2007
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hm... or maybe you're trying to find today's date in another month/year? I'm not sure what's the best approach for that. Maybe using DateDiff() to find the wholes months difference. Then using DateAdd(..) to subtract the number of months to calculate the desired date.

  4. #4
    SitePoint Addict capescafe's Avatar
    Join Date
    Dec 2004
    Location
    Bellevue, WA
    Posts
    222
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Ok thanks. It works today but that's because it's the 1st. I guess I'll have to wait now until the end of this month to try fixing it.

    Thanks for the input.
    Carolyn (cape's cafe)
    Twitter | My Treehouse Profile | eBookFling

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,426
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    I wouldn't wait on the calendar to roll around. I'd take the date, manipulate it to the test date, and test using that.

    Up to you of course, maybe you're busy enough and/or have lots of patience.

  6. #6
    SitePoint Evangelist
    Join Date
    Mar 2007
    Posts
    584
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I wouldn't wait either. But then I don't like those kind of surprises ;-)

    Also, you might post your final code to help anyone reading this thread in the future.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •