Using Dates with Greater Than / Equal To Operators

Why does this code execute a message box displaying, “Late”? I would have expected, “Today”, but I am lacking sleep too.

  Dim oneDay as Integer
  Dim yesterday as new date
  Dim today as new date
  Dim tomorrow as new date
  
  oneDay = ( 24 * 60 * 60 )
  yesterday.TotalSeconds = today.TotalSeconds - oneDay
  tomorrow.TotalSeconds = today.TotalSeconds + oneDay
  
  select case today.ShortDate
    
  case Is <= yesterday.ShortDate
    msgbox "Late"
    
  case today.ShortDate
    msgbox "Today"
    
  case tomorrow.ShortDate
    msgbox "Tomorrow"
    
  end select

Why is your first select case

 case Is <= yesterday.ShortDate

If you make it

 case yesterday.ShortDate

You get the good result.

Also, why not simply use the Day property instead of totalSecond ?

Dim oneDay as Integer Dim yesterday as new date yesterday.Day = yesterday.day-1 system.DebugLog yesterday.ShortDate Dim today as new date system.DebugLog today.ShortDate Dim tomorrow as new date tomorrow.Day = tomorrow.day+1

or why not compare the SQLDate string property?

  Dim yesterday as new date
 
  Dim tomorrow as new date
  
  yesterday.day= today.day-1
  tomorrow.day = today.day+1
  
  select case today.sqldate
    
  case Is <=yesterday.sqldate
    msgbox "Late"
    
  case today.today.sqldate
    msgbox "Today"
    
  case tomorrow.sqldate
    msgbox "Tomorrow"
    
  end select

and <= makes sense… it is not = yesterday… is is yesterday or BEFORE (ie. its late)

BUT… it will never work… as you are ALWAYS comparing to TODAY

Shortdate isn’t suitable for comparison. Use sqldate or totalseconds.

Xojo can handle complete date objects… i think he use totalseconds.

like
if date1 < date2 then…

But be sure to set hours and minutes to start/end of day first

[quote=193359:@Dave S]or why not compare the SQLDate string property?

  Dim yesterday as new date
 
  Dim tomorrow as new date
  
  yesterday.day= today.day-1
  tomorrow.day = today.day+1
  
  select case today.sqldate
    
  case Is <=yesterday.sqldate
    msgbox "Late"
    
  case today.today.sqldate
    msgbox "Today"
    
  case tomorrow.sqldate
    msgbox "Tomorrow"
    
  end select

[/quote]
SQLDate is what I needed.
I’m surprised everyone uses .Day, since I thought it was considered unreliable. Maybe that has since changed.

Exactly.

[quote=193359:@Dave S]
BUT… it will never work… as you are ALWAYS comparing to TODAY[/quote]
Right. That was just for example purposes.

Thanks Dave.

I could find no bug report of any kind for Day. There are numerous bug reports for Date, but mostly about date format, and local time.

That said using TotalSeconds is just another way of doing it, and Day is just a convenient way of representing a duration in human terms.