Results 1 to 3 of 3

Thread: date comparison

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    Canada
    Posts
    20

    Exclamation

    Does anyone know how to compare dates in VBSCript in the format mm/dd/yyyy?

    In VB just simply declare the variables as
    dim a as date
    dim b as date
    but what do you do in VBSCript?

    the following code will generate the text "a is greater than b" - obviously not true
    <%
    dim a,b
    a= "05/23/1999"
    b= "01/23/2000"

    if a > b then
    response.write "a is greater than b"
    elseif a = b then
    response.write "a is equal to b"
    else
    response.write "a is less than b"
    end if
    %>

    any help is appreciated!

    B

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    It can be done very easily. In your code your dates are actually strings, so all you have to do is to convert them to date:
    Code:
    Dim a
    Dim b 
    
    a= "05/23/1999" 
    b= "01/23/2000" 
    
    If CDate(a) > CDate(b) Then 
        Response.Write "a is greater than b" 
    Elseif CDate(a) = CDate(b) then 
        Response.Write "a is equal to b" 
    Else 
        Response.Write "a is less than b" 
    End If

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    Canada
    Posts
    20

    Smile

    Brilliant - thanks for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width