Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Converting String to Date

Posted on 2004-11-01
3
Medium Priority
?
268 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:kwcowboy1226
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Expert Comment

by:bramsquad
ID: 12465430
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
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 12466228
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
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 2000 total points
ID: 12466269
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Introduction to Processes

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question