Solved

Converting String to Date

Posted on 2004-11-01
265 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
Question by:kwcowboy1226
    3 Comments
     
    LVL 8

    Expert Comment

    by:bramsquad
    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
    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:
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    933 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now