locked
Date conditionals not working?? RRS feed

  • Question

  • User-502227870 posted

    I am trying to do something, which I seems to be pretty simple, but no matter how I try, one thing or another doesn't seem to work.  All I want to do is check if the current date is 14 days prior to an expiration date display how many days until the expiration date, but if the current date is past the expiration date, display an expiration notice.

    If have tried a bunch of different ways, but none seem to work.  Here is the latest variation that is not working:

    Dim ExpirationDate as Date = "07/01/2012"
    Dim ExpirationNoticeDate as Date = ExpirationDate.AddDays(-14)
    
    If Date.Today > ExpirationNoticeDate AND Date.Today < ExpirationDate Then
      label.text = "NOTICE: expiration date in " & (date.Today - ExppirationDate).Days & " days."
    Else
      IF Date.Compare(expirationDate, Date.Today) >= 0 then
        label.text = "Uh oh, you have expired!!"
    end if
    end if



    Friday, May 4, 2012 7:40 AM

Answers

  • User21295764 posted

    this maybe:

            Dim ExpirationDate As Date = New Date(2012, 7, 1)
            If DateDiff(DateInterval.Day, Today, ExpirationDate) < 14 Then
    
                label.text = "Expired..."
            Else
                label.text = "NOTICE..."
    
            End If
    

     

    you may need to switch the dayes in the DateDiff function, it's always a gamble for me.

    Basically the use of DateDiff to calculate the number of days between two dates is the point i want to make.

     


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 4, 2012 8:56 AM