Jump to content

[SOLVED] Time Stamp - Midnight + Days


Fruct0se

Recommended Posts

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

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

$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 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.