Archive: IntOp divide wrong/unexpected answer


IntOp divide wrong/unexpected answer
MessageBox MB_OK "Incoming date is $0" >> displays 020307
IntOp $R1 $0 / 100
MessageBox MB_OK "date1 is $0 : $R1" >> displays 020307
:83

So, I figured out that NSIS uses standard notation with an extra 0 on the front is Octal. How do I tell NSIS this is a decimal number?

Thanks,

-Kevin


there is no IntOp flag for this, but it really should exist, so you should add a feature request for it


Kevin,
In your case you are looking at dates and only have to worry about a single leading zero. You can code a test for that and eliminate that single zero like this:

StrCpy $R1 $0 1
${If} $R1 = 0
StrCpy $0 $0 "" 1
${EndIf}
IntOp $R1 $0 / 100

Don

more easily, if you're sure of the format DDMMYY
just do a StrCpy $R1 $0 4 to obtain DDMM


Awesome - I got it, thanks for the he'p.

So, I set the date as I compile (and append this to the install .exe file) - and since this is !define, should be embedded in the installer as well, right?

I then compare this to a registry entry (which I would have written to before on previous installs), and I can detect upgrades, as well as roll-backs.

!define /date DATE "%m%d%y"

Function ConvertDateToYYMMDD
Pop $0

StrCpy $R1 $0 4 ;Create MMDD (from MMDDYY)
StrCpy $R2 $0 "" -2 ;Calculate YY
StrCpy $0 "$R2$R1"

Push $0
FunctionEnd


Function IsDateNewer
Pop $R4
Pop $R3

Push $R3
Call ConvertDateToYYMMDD
Pop $R3

Push $R4
Call ConvertDateToYYMMDD
Pop $R4

IntCmp $R3 $R4 GT LTOE GT
LTOE:
StrCpy $0 "false"
Push $0
return
GT:
StrCpy $0 "true"
Push $0
FunctionEnd


Why not use date format "%Y%m%d" directly ? (YYYYMMDD)
then you can directly read/write the value from registry (as integer or string as you prefer), and proceed to integer comparison
(and year with century never starts with '0')