kwcowboy1226
asked on
Converting String to Date
if intCurrentMonth <= 12 then
dtCurrentStartDate = intCurrentMonth & "/" & 01 & "/" & 2004
if NOT intCurrentMonth = 9 and NOT intCurrentMonth = 11 then
dtCurrentEndDate = intCurrentMonth & "/" & 31 & "/" & 2004
else
dtCurrentEndDate = intCurrentMonth & "/" & 30 & "/" & 2004
end if
strSQL = "Calendar.dbo.kwsSP_GetEve ntsbyTesti ngDate '" & Cdate(dtCurrentStartDate) & "', '" & CDate(dttCurrentEndDate) & "'"
I am receiving this error:
Technical Information (for support personnel)
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'Cdate'
/katynet/calendar/tests_by _month.asp , line 269
Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)
Page:
GET /katynet/calendar/tests_by _month.asp
Time:
Monday, November 01, 2004, 11:32:10 AM
More information:
Microsoft Support
dtCurrentStartDate = intCurrentMonth & "/" & 01 & "/" & 2004
if NOT intCurrentMonth = 9 and NOT intCurrentMonth = 11 then
dtCurrentEndDate = intCurrentMonth & "/" & 31 & "/" & 2004
else
dtCurrentEndDate = intCurrentMonth & "/" & 30 & "/" & 2004
end if
strSQL = "Calendar.dbo.kwsSP_GetEve
I am receiving this error:
Technical Information (for support personnel)
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'Cdate'
/katynet/calendar/tests_by
Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)
Page:
GET /katynet/calendar/tests_by
Time:
Monday, November 01, 2004, 11:32:10 AM
More information:
Microsoft Support
your logic in this statement is flawed:
if NOT intCurrentMonth = 9 and NOT intCurrentMonth = 11 then
dtCurrentEndDate = intCurrentMonth & "/" & 31 & "/" & 2004
else
dtCurrentEndDate = intCurrentMonth & "/" & 30 & "/" & 2004
end if
since months 9 and 11 are NOT the only months that have 30 days, and months 1-8, 10, and 12 are NOT the only months that have 31 days (what about February (intCurrentMonth =2, which has 28 or 29 days)
Months 4,6, 9 and 11 ALL have 30 days,
Months 1,3,5,7,8, 10 and 12 ALL have 31 days
Month 2 has 28 or 29 (Leap Year, which 2004 was)
AW
if NOT intCurrentMonth = 9 and NOT intCurrentMonth = 11 then
dtCurrentEndDate = intCurrentMonth & "/" & 31 & "/" & 2004
else
dtCurrentEndDate = intCurrentMonth & "/" & 30 & "/" & 2004
end if
since months 9 and 11 are NOT the only months that have 30 days, and months 1-8, 10, and 12 are NOT the only months that have 31 days (what about February (intCurrentMonth =2, which has 28 or 29 days)
Months 4,6, 9 and 11 ALL have 30 days,
Months 1,3,5,7,8, 10 and 12 ALL have 31 days
Month 2 has 28 or 29 (Leap Year, which 2004 was)
AW
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
strSQL = "Calendar.dbo.kwsSP_GetEve
what you are trying to do is to concatinate a string with a date.
either keep it a string, or if you wanted formatted in someway convert it to a date, format it, and then convert it back to a string.
try this...
if intCurrentMonth <= 12 then
'here you are doing an implicit conversion also - keep everything as a string
dtCurrentStartDate = CStr(intCurrentMonth) & "/01/2004"
if NOT intCurrentMonth = 9 and NOT intCurrentMonth = 11 then
dtCurrentEndDate = CStr(intCurrentMonth) & "/31/2004"
else
dtCurrentEndDate = CStr(intCurrentMonth) & "/30/2004"
end if
'take away the date conversion
strSQL = "Calendar.dbo.kwsSP_GetEve
~b