Fruct0se Posted November 8, 2008 Share Posted November 8, 2008 How would I go about getting a time stamp for midnight of the current day, then another timestamp for the current day at midnight + two days? Quote Link to comment Share on other sites More sharing options...
Yesideez Posted November 8, 2008 Share Posted November 8, 2008 Without accessing a MySQL database... $dt=explode(':',date('d:m:Y',time())); $midnight1=mktime(0,0,0,$dt[1],$dt[0],$dt[2]); $midnight2=$midnight1+(2*24*60*60); Not checked. Quote Link to comment Share on other sites More sharing options...
Mchl Posted November 8, 2008 Share Posted November 8, 2008 strtotime(date('Y F d')); strtotime(date('Y F d',strtotime("+2 days"))); Quote Link to comment Share on other sites More sharing options...
Yesideez Posted November 8, 2008 Share Posted November 8, 2008 Mchl, what about the hours, minutes and seconds? Does that insert 0 for them because they're not specified? Quote Link to comment Share on other sites More sharing options...
Mchl Posted November 8, 2008 Share Posted November 8, 2008 Did not test that, but yeah, it should. Quote Link to comment Share on other sites More sharing options...
Fruct0se Posted November 8, 2008 Author Share Posted November 8, 2008 Without accessing a MySQL database... $dt=explode(':',date('d:m:Y',time())); $midnight1=mktime(0,0,0,$dt[1],$dt[0],$dt[2]); $midnight2=$midnight1+(2*24*60*60); Not checked. this outputs: 1226177782 - current time 1226131200 - midnight 1 1226304000 - midnight 2 midnight 1 is less than the current days midnight time Quote Link to comment Share on other sites More sharing options...
Yesideez Posted November 8, 2008 Share Posted November 8, 2008 Just wrote this: <?php $dt=explode(':',date('j:n:Y',time())); $midnight1=mktime(0,0,0,$dt[1],$dt[0],$dt[2]); $midnight2=$midnight1+(2*24*60*60); for ($i=0;$i<count($dt);$i++) { echo $i.': '.$dt[$i].'<br />'; } echo $midnight1.'<br />'; echo $midnight2.'<br />'; echo date('H:i:s d-m-Y',time()).'<br />'; echo date('H:i:s d-m-Y',$midnight1).'<br />'; echo date('H:i:s d-m-Y',$midnight2); ?> Gives this: 0: 8 1: 11 2: 2008 1226120400 1226293200 16:13:39 08-11-2008 00:00:00 08-11-2008 00:00:00 10-11-2008 Quote Link to comment Share on other sites More sharing options...
Yesideez Posted November 8, 2008 Share Posted November 8, 2008 Just tried Mchl's code and got this: 00:00:00 01-05-2014 00:00:00 30-04-2016 Quote Link to comment Share on other sites More sharing options...
Mchl Posted November 8, 2008 Share Posted November 8, 2008 Of all date formats listed on gnu.org I must have chosen one not suppported by strtotime. How about this? strtotime(date('d M y')); strtotime(date('d M y',strtotime("+2 days"))); Quote Link to comment Share on other sites More sharing options...
Barand Posted November 8, 2008 Share Posted November 8, 2008 $midnight_today = mktime(0,0,0); $plus_2_days = strtotime('+2 days', $midnight_today); echo $midnight_today, '<br/>'; // 1226102400 echo $plus_2_days, '<br/>'; // 1226275200 /** * check */ echo date('Y-m-d H:i:s', $midnight_today), '<br/>'; // 2008-11-08 00:00:00 echo date('Y-m-d H:i:s', $plus_2_days), '<br/>'; // 2008-11-10 00:00:00 Quote Link to comment Share on other sites More sharing options...
Fruct0se Posted November 9, 2008 Author Share Posted November 9, 2008 Thanks everyone, works perfect! 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.