![]() |
Date Routine
This may be old news to some but at the same time may be of value to someone else.
I was recently faced with creating a date stamp for the previous day's date. Using some hints found online, I concocted the following routine which works nicely: ### function to build dstamp (date stamp for previous day's date) my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time - 86400); $mon = $mon + 1; $year = $year + 1900; $dstamp = sprintf "%04d%02d%02d", $year, $mon, $mday; ### end of dstamp function The nice thing is that the value 86400 in the call to 'localtime' is equivalent to one (1) day ... so, by adjusting this value, you can create the same sort of date stamp (format is YYYYMMDD) for any offset. Enjoy! Tom |
Will it take into account Daylight Savings time too ?
suppose yesterday was NON DST and today is a DST ? |
Subtracting 86400 from the time will work most of the time, but not all of the time. If you need accuracy, use a module like DateTime:
:
|
| All times are GMT -5. The time now is 10:10 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC