A

#### Anonymous

##### Guest
Doesn't any one have a simple code that I can have.

date("Y-m-d H:i:s") + (1800 * 24);//this doesnt work ;/ but i need to have 24 hours after date for a check.

Thanks for taking the time i hope some one can help me out. Dont warry about it if you dont have some thing already made.

LMAO every time i ask some thing i figure it out lol ;/ o well here it is

Code:
``````<?php
\$datetime = date("Y-m-d H:i:s");
\$h24 = time() + (1800 * 24);
echo \$datetime;
echo '<br />';
echo date('Y-m-d', \$h24).' '.date("H:i:s");
?>``````

Actually, you're adding 12 hours. 1 hour is 60 minutes x 60 seconds is 3600 seconds...

To prevent mistakes like these, just write the formula in full:
Code:
``````<?php
\$h24 = time() + (24 * 60 * 60);
// or 2 days:
\$h48 = time() + (2 * 24 * 60 * 60);
?>``````

There is another problem by the way, switching from and to daylight saving time. If today is in DST and tomorrow isn't, you're adding 23 hours effectively... You can use date("I") to determine if the current day is in DST, and if the next day is in DST.

Code:
``````<?php
\$today = mktime(12, 0, 0);
\$tomorrow = \$today + (24 * 60 * 60);
\$dstToday = intval(date("I"));
\$dstTomorrow = intval(date("I"));
\$hoursToAdd = 24 + \$dstToday - \$dstTomorrow;
\$h24 = time() + (\$hoursToAdd * 60 * 60);
?>``````

If it's 00:10 now, dst, and tonight is the start of dst, 24 hours ahead would still be the same date. Therefor I set the time to 12:00, before calculating dst.

Coditor

Code:
``````<?
\$time_stamp = gmtdate();
list(\$date,\$time) = explode(" ",\$time_stamp);
list(\$y,\$m,\$d) = explode("-",\$date);
list(\$h,\$min,\$s) = explode(":",\$time);
\$gmtdiff = date("O");
\$gmt_hours_diff = substr(\$gmtdiff, 1, 2);
\$gmt_minutes_diff = substr(\$gmtdiff, 3, 2);
\$h = \$h + \$gmt_hours_diff + 24;
\$min = \$min + \$gmt_minutes_diff;
\$formatted_date = date("d-m-Y H:i:s", mktime(\$h,\$min,\$s,\$m,\$d,\$y));
?>``````

That still doesn't take DST into account... Unless you get date("O") for both today and tomorrow...