Here are macros that extract date and time from %t:
macro months [dayscount]
{
forward
if DAY > dayscount
DAY = DAY-dayscount
MONTH = MONTH+1
forward
end if
}
TIME = %T
DAY = TIME/(24*3600)
HOUR = (TIME - (DAY*24*3600))/3600
MINUTES = (TIME - DAY*24*3600 - HOUR * 3600)/60
SECONDS = TIME - DAY*24*60*60 - HOUR * 60*60 - MINUTES*60
DAY = DAY - (DAY+365)/(3*365+366)
YEAR = 1970+DAY/365
DAY = DAY mod 365 + 1
MONTH = 1
if YEAR mod 4 = 0
FEBDAYS=29
else
FEBDAYS=28
end if
months 31,FEBDAYS,31,30,31,30,31,31,30,31,30,31
macro num_to_db num, digits {
common
local ..lbl, ..ptr, ..dig, ..num
..lbl:
rb digits
..ptr = ..lbl + digits - 1
..num = num
repeat digits
..dig = (..num mod 10) + $30
..num = ..num / 10
store byte ..dig at ..ptr
..ptr = ..ptr - 1
end repeat
}
But if you need local time, you have to adjust %t before making calculations (for example my zone is GMT+2, so I'd have to add 2*3600 to %t). However if you'd like to have timezone-independed code , you should get system timezone using some API, then adjust %t and calculate at runtime.