WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Time - Timer and Date Functions
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Yesterday Script - Subtract a Day

Keywords:     Timeymdhms()

This script takes the current date and subtracts one day from it. In current versions of WinBatch, you can use the new function, TimeSubract, to do the same thing.

; Subtract 1 day from 9/1/2000 (at midnight)
newtime=TimeSubtract("2000:09:01:00:00:00", "0000:00:01:00:00:00")
Message("One day before 09/01/2000", newtime)

Old way

date=Timeymdhms()
date="96:01:01:00:00:00"   ;for testing purposes.
year=ItemExtract(1,date,":")
month=ItemExtract(2,date,":")
day=ItemExtract(3,date,":")
hour=ItemExtract(4,date,":")
mins=ItemExtract(5,date,":")
sec=ItemExtract(6,date,":")

If day != 1           ;test to see if the day is the first.  Subtract one day
     day=day-01        ;and concantenate the parts together.
else 
     If month ==1      ;test to see if the month is Jan.  If so, change the year
          year=year-1
          month=12
          day=31  
     else              ;check to see which month it is and change the last day 
          month=month-1        ;of the month accordingly.
          switch month
               case 2
                    ; Leap Year Info
                    ; 1) Every 4000 years Is NOT a leap year
                    ; 2) Every 1000 years is
                    ; 3) Every 100  years is NOT
                    ; 4) Every 4 years is
                    ;
                    ; Simple mod 4 test below is good from 1901 to 2099
                    ; other wise it has to get more complicated
                    if  (year mod 4) == 0
                       day=29
                    endif
                    break
               case 4 

               case 6

               case 9

               case 11
                    day=30
                    break
               case month
                    day=31
                    break     
          endswitch 
     endif     
endif 

TheDay=StrCat(year, ":", month, ":", day, ":", hour, ":", mins, ":", sec)

Message("We're done, this is the new day", Theday)


Article ID:   W13897
Filename:   Yesterday Script - Subtract a Day.txt
File Created: 2001:01:09:11:18:18
Last Updated: 2001:01:09:11:18:18