more useful options | |
PerlMonks |
Re: Check current time between range of dates and timesby Marshall (Canon) |
on May 13, 2009 at 23:07 UTC ( [id://763946]=note: print w/replies, xml ) | Need Help?? |
Epoch time is the number of seconds +or- from the epoch and is a signed integer value of some precision x. It is possible to do "time math" in seconds on epoch times. Use date/time string to create an epoch time and then add 24*60*60 seconds to it to get 24 hours from then if you want 23.5 hours then add(or subtract) 24*60*60-(30*60)..keep things in whole numbers (don't use .3 for a third of a day, use 8 hours *60 min*60 sec, etc... So to see if your proposed date is in-between those times, convert it to epoch seconds also and do a numeric comparison. You can use the stat func to figure out if that proposed date is Monday in your local time. I would normally do everything in GMT or UTC as it is known today. Of course I may have missed something here... Update: oh, another point, when writing log files, etc. I use a format like this: 2007-10-06 1647. If leading zeroes are enforced for both date and time, then a simple alpha comparison or sort will get the right answer. To add 30 minutes to 2007-10-06 1647, I convert to epoch, add 30*60, then convert back to string (all this 24 hours, 60 minutes stuff is messy).
In Section
Seekers of Perl Wisdom
|
|