I get some times from a database and I am trying to store them by month, using the epoch form. So I could have some random times like:
1354120744
1328978360
1297388332
and for each one I want to find the epoch value which represents the 1st of that month so for the last timestamp it would be:
1296518400
(using lovely epochconverter.com
).
I know that I can use POSIX mktime
to reduce the timestamp down to days, mins etc and change them accordingly etc as was the answer to a post I did a while ago: How to go back months in Perl taking account of different days in month?
The trouble I have with that is that while I can zero times, I'm worried that by changing the date the day of week will not match up, so essentially making an invalid date. This may be an unnecessary worry; I don't know if it would make a difference having the wrong day of week if the times are validated.
I couldn't see any other POSIX methods which seemed useful. Any help appreciated!