capescafe — 2010-06-30T17:39:07-04:00 — #1
Here is the cf code causing the problem in the error msg:
<cfset tNow = CreateDateTime(#url.year#, #url.month#, #day(now())#, 00,00,00)>
<cfset tNow = CreateDateTime(#form.year#, #form.month#, #day(now())#, 00,00,00)>
<cfset tNow = Now()>
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?
system — 2010-07-02T02:41:39-04:00 — #2
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.
mittineague — 2010-07-01T17:59:30-04:00 — #3
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.
capescafe — 2010-07-01T17:29:26-04:00 — #4
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.
system — 2010-06-30T20:27:30-04:00 — #5
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.
system — 2010-06-30T17:55:05-04:00 — #6
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()