Results 1 to 8 of 8

Thread: date problem

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    date problem

    I'm testing to see if a date is current. This code works fine, except it returns the error message when todays date is chosen. I'm using the < sign, why is it returning the error message for todays date?

    Code:
    If CDate(txtIntDisStartDate.Text) < Now Then
    lblErr.Text = "Display Start Date must be current"
    Exit Sub
    End If

  2. #2
    Member
    Join Date
    Sep 2002
    Posts
    37
    Try

    If CDate(txtIntDisStartDate.Text) < Now.Date Then
    lblErr.Text = "Display Start Date must be current"
    Exit Sub
    End If


    This should compare just the date and not include the time

    Harold Hoffman

  3. #3
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    HAROLD HOFFMAN is quite correct, your CDate convertion gives you a value wich has the time 00:00 and VERY often that will be smaller than the now value that gives you the time where you call the function. So either try what HAROLD suggested or maybe convert all dates to short dates with Date.ToShortDateString and compare strings.

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    VB Code:
    1. Dim tody As Date
    2. Dim mydate As Date
    3. mydate = tody.Today
    4. If mydate = tody.Today Then
    5. 'put your code
    6. End If
    would this helps !!

  5. #5

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    thanks Harold, that worked...I need to check if a date is one day after another date selected...is this correct?

    Code:
     If CDate(txtPreBidOpenDate.Text) = DateAdd(DateInterval.Day, 1, CDate(txtBidOpenDate.Text))

  6. #6

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    thanks Harold, that worked...I need to check if a date is one day after another date selected...is this correct?

    Code:
     If CDate(txtPreBidOpenDate.Text) = DateAdd(DateInterval.Day, 1, CDate(txtBidOpenDate.Text))

  7. #7
    Member
    Join Date
    Sep 2002
    Posts
    37
    I would probably use the following to make sure that you are comparing only the date component and not the time component if there is one.

    If CDate(txtPreBidOpenDate.Text).Date = DateAdd(DateInterval.Day, 1, CDate(txtBidOpenDate.Text).Date)


    Harold Hoffman

  8. #8

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    thanks

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