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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

$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 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.