subtracting dates

How can I subtract 1 day from a date or add 1 day to date?

dim dt as new date msgbox dt.sqldatetime dt.totalseconds = dt.totalseconds - (24 * 60 * 60) msgbox dt.sqldatetime

thank you very much

I have created a large number of date routines and included them in a single module.

You can download this from here: https://dl.dropboxusercontent.com/u/10747116/RealStudioClasses/sbExtendsDate.xojo_binary_code.zip

dim dt as new date
msgbox dt.sqldatetime
dt.day= dt.day- 1
msgbox dt.sqldatetime

[quote=82785:@Tim Hare]dim dt as new date
msgbox dt.sqldatetime
dt.day= dt.day- 1
msgbox dt.sqldatetime[/quote]
Tim

This is a solution to the OP’s question and is absolutely correct. However, I thought he might need a little guidance on the key underlying TotalSeconds property that drives all the date routines. This is why I didn’t use 86400 as the minus number but (24 * 60 * 60).

I normally use the different properties like day and month to calc, not total seconds.

Here is a different solution

  Dim totalSec As Double
  Dim today as New Date
  Dim mySetdate as New Date
  Dim dayStr As String
  
  //Your entered date
  mySetdate.Year = 2013  // (calculations within current year you can comment it out //mySetdate.Year = 2013)
  mySetdate.Month = 09
  mySetdate.Day = 01
  mySetdate.Hour = 10
  mySetdate.Minute = 00
  mySetdate.Second = 00
  
  dayStr = "Today Total Seconds:   "+str(today.TotalSeconds)+EndOfLine
  dayStr = dayStr +"Date: "+today.LongDate +"  Time: "+today.LongTime +EndOfLine+EndOfLine
  
  
  dayStr = dayStr +"Entered day Total Seconds:   "+str( mySetdate.TotalSeconds)+EndOfLine
  dayStr = dayStr +"Date: "+ mySetdate.LongDate +"  Time: "+ mySetdate.LongTime +EndOfLine+EndOfLine
  
  If mySetdate < today Then
    //That's before today!
    TotalSec = today.TotalSeconds -  mySetdate.TotalSeconds
    dayStr = dayStr +"Sub Seconds:   "+str( TotalSec)+EndOfLine+EndOfLine
  Else
    // Today or the future
    TotalSec = mySetdate.TotalSeconds - today.TotalSeconds
    dayStr = dayStr +"Sub Seconds:   "+str( TotalSec)+EndOfLine+EndOfLine
  End If
  
  msgbox dayStr