Calendar gives error only for month of February?

Here is the cf code causing the problem in the error msg:

<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?

Yeah, I wouldn’t wait either. But then I don’t like those kind of surprises :wink:

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

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.

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.

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.

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 :wink:

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()