Archive: Add 30 days to current date ?


Add 30 days to current date ?
Hello,

I want to write the current date into an ini-file but 30 days later. With GetTime I already got the date but how can I count 30 days on ?

How can I realize that with NSIS ?

Thanks in forward.

Bye Defcon0.


My way that I like to do is by using the Math plug-in date & time functions. First convert the current time to seconds, then use another function to add 30 days in seconds to it, then convert it back to a date.

I'll prepare the message with the code solution with this.

[EDIT]This is the test script I prepared:

OutFile Test.exe

Section
;Math plug-in time functions initialization
;============================================

Math::Script /NOUNLOAD `IsLeapYear(a, b,c) (#[mdf(a/4.0,c) == 0, #[mdf(a/100.0,c) > 0, b = 1, #[mdf(a/400.0,c) == 0, b = 1, b = 0]],b = 0];b)`
Math::Script /NOUNLOAD `MinToSec(a) (a*60)`
Math::Script /NOUNLOAD `HourToSec(a) (a*MinToSec(60))`
Math::Script /NOUNLOAD `DayToSec(a) (a*HourToSec(24))`
Math::Script /NOUNLOAD `MonthToSec(a,b, c) (a--;c=a*DayToSec(31);#[a>=1,#[IsLeapYear(b)==1,c-=DayToSec(2),c-=DayToSec(3)]];#[a>=3, c-=DayToSec(1)];#[a>=5, c-=DayToSec(1)];#[a>=8, c-=DayToSec(1)];#[a>=10, c-=DayToSec(1)];#[a>11, c=0];c)`
Math::Script /NOUNLOAD `YearToSec(a,b, c) (c=0;#{++b<=a,#[IsLeapYear(a-1),c+=DayToSec(366),c+=DayToSec(365)]};c)`

Math::Script /NOUNLOAD `DateToSec(a,b,c,d,e,f,g, h) (h=YearToSec(g, a)+MonthToSec(f, a)+DayToSec(e-1)+HourToSec(b)+MinToSec(c)+d;h)`

Math::Script /NOUNLOAD `SecToYear(a,b,&c, d) (d=b;#{*c=#[IsLeapYear(d),DayToSec(366),DayToSec(365)];a>=*c,a-=*c;d++};*c=a;d)`
Math::Script /NOUNLOAD `SecToMonth(a,b,&c, d,e) (d=0; e={31,28,31,30,31,30,31,31,30,31,30,31,0};#{#[d>=12,*c=a+1;d=-1,*c=e[d]*DayToSec(1)];#[(d==1)&&(IsLeapYear(b)),*c+=DayToSec(1)];a>=*c,a-=*c;d++};*c=a;++d)`
Math::Script /NOUNLOAD `SecToDay(a,&b) (*b=a%DayToSec(1); a=a/DayToSec(1))`
Math::Script /NOUNLOAD `SecToHour(a,&b) (*b=a%HourToSec(1); a=a/HourToSec(1))`
Math::Script /NOUNLOAD `SecToMin(a,&b) (*b=a%MinToSec(1); a=a/MinToSec(1))`

Math::Script /NOUNLOAD `SecToDate(a,b,&c,&d,&e,&f,&g,&h, i) (*h=SecToYear(a,b,i);a=i;*g=SecToMonth(a,b,i);a=i;*f=SecToDay(a,i)+1;a=i;*c=SecToHour(a,i);a=i;*d=SecToMin(a,*e))`

;Call those functions
;======================

;Parameters (push last parameter from math function first)
Push "2006" ;Year
Push "1" ;Month
Push "1" ;Day
Push "0" ;Second
Push "0" ;Minute
Push "0" ;Hour
Push "2006" ;InitYear (year at which the counting of seconds start)
Math::Script /NOUNLOAD `NS=DateToSec(NS,NS,NS,NS,NS,NS,NS)`
; Pop $0 ;Seconds

; Push $0 ;Seconds
Push "30" ;Days to add
Math::Script /NOUNLOAD `NS=DayToSec(NS) + NS`
Pop $0 ;Resulting seconds

Push "2006" ;InitYear
Push $0 ;Seconds
Math::Script /NOUNLOAD `SecToDate(NS,NS,NS,NS,NS,NS,NS,NS)`
Pop $1 ;Hour
Pop $2 ;Minute
Pop $3 ;Second
Pop $4 ;Day
Pop $5 ;Month
Pop $6 ;Year

DetailPrint "$1:$2:$3 $4/$5/$6"
SectionEnd
[/EDIT]

[EDIT #2]Fixed a little mistake in expressing the years (different "InitYear" values).[/EDIT #2]

That would be great. Thanks.
But please make a new reply so that I get an email notification.


Done. Code is in my first post.


OK. Thanks. I'll test it