JasonO Posted February 10, 2010 Share Posted February 10, 2010 Hi everyone, How would I go about getting the timestamp of the current day, rounded to the most recent time of 00:00? For example, If I used 10/02/2010 at 14:43:32 it would give me a timestamp for that by default (as that is the current time of posting this). However, how would I get it to get the timestamp for 10/02/2010 00:00 ? Is there a way to easily round the earliest 00:00 time? I don't want it to round ahead as I can't time travel. Thanks. Quote Link to comment Share on other sites More sharing options...
gwolgamott Posted February 10, 2010 Share Posted February 10, 2010 Sure, just get the current date and then when displaying it add the 00:00. Why would you need the time-stamp if you are using the time as midnight every time? Just get the current date. Quote Link to comment Share on other sites More sharing options...
JasonO Posted February 10, 2010 Author Share Posted February 10, 2010 I thought the timestamp is the number of seconds since 1st Janurary 1970? I would like to store the date with the time being 00:00, otherwise I'll have the problem when the cron job runs the script just after midnight (runs every day at 00:05), it won't see the time as being 'today'. If the number of seconds at midnight is 1000 for example, at 1 minute past midnight it would be 1060. In 10 minutes it would be 1600. If I wanted to see if anything of that day was due, it wouldn't work correctly as 1000 is less than 1060 for example. Damn, I'm finding this really hard to explain. Heh. Is there a better way of doing it then? I just wanted to go by the current concept of that if the checking script run by the cron has a current time thats after the one in the database, it would mean that the database row needs updating. If the time in the database is at, say 2PM, the cron job wont pick that up until the next cron. Sorry I'm not very good at explaining it :| Quote Link to comment Share on other sites More sharing options...
gwolgamott Posted February 10, 2010 Share Posted February 10, 2010 Oh ok, I see what you mean then. My bad actually, misread what you wanted. Yeah there is a way to do that but I do not remember how. give me a few and I'll find it. Quote Link to comment Share on other sites More sharing options...
gwolgamott Posted February 10, 2010 Share Posted February 10, 2010 There you go this should help you out. http://www.w3schools.com/php/func_date_mktime.asp let me know if you need to know help with that. Quote Link to comment Share on other sites More sharing options...
salathe Posted February 10, 2010 Share Posted February 10, 2010 $midnight = strtotime('midnight'); echo date('r', $midnight); // Tue, 10 Feb 2009 00:00:00 +0000 Quote Link to comment Share on other sites More sharing options...
gwolgamott Posted February 10, 2010 Share Posted February 10, 2010 $midnight = strtotime('midnight'); echo date('r', $midnight); // Tue, 10 Feb 2009 00:00:00 +0000 Sweet didn't know that. Now I do... http://php.net/manual/en/function.strtotime.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.