Hi,
I have a string holding the date, eg, "24/05/2011"
I want to take exactly 1 year off the date (under certain conditions), and then write it back as a string
Is there a date API call to enable me to do this?
Many thanks,
Brian
Hi Brian, try this one - it assumes that the year is the third element:
declare import,sscanf(...)
declare import,sprintf(...)
sub decrement_year(string date)
int d,m,y
sscanf(date, "%d/%d/%d",&d,&m,&y)
sprintf(date, "%02d/%02d/%d",d,m,y-1)
endsub
' example
string date = "24/05/2011"
print date
decrement_year(date)
print date
Well, Sapero, you've done it again!
Thanks for an example I could actually understand, and which worked first time
Thanks again,
Brian
Just a heads up here that this will be incorrect for a specific case of in a leap year.
i.e. "29/02/2000" minus 1 year would give "29/02/1999" which doesn't exist! :o
don't know if you'd want it to give "01/03/1999" or "28/02/1999", but you'd have to code in extra checks in either case. :-\
Dennis,
I wondered about that. Might have a look at leap year dates past and present,
and make sure that the calculated date doesn't land on one of those. I can always
move it forward or back one day if it does
Thanks for the reminder,
Brian