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_GetEventsbyTestingDate '" & 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
kwcowboy1226Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bramsquadCommented:
in this statement

strSQL = "Calendar.dbo.kwsSP_GetEventsbyTestingDate '" & Cdate(dtCurrentStartDate)  & "', '" & CDate(dttCurrentEndDate) & "'"

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_GetEventsbyTestingDate '" & dtCurrentStartDate  & "', '" & dttCurrentEndDate & "'"

~b
0
Arthur_WoodCommented:
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

0
Arthur_WoodCommented:
and the logic flaw would lead yto you creating an invalid value for

dtCurrentStartDate

so that

Cdate(dtCurrentStartDate)  would generate a run-time error.


AW
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.