Forum Moderators: coopster

Message Too Old, No Replies

date function

         

hal12b

10:00 pm on Dec 14, 2008 (gmt 0)

10+ Year Member



Can somebody help me out?

This code displays the current day/month/year and time
$today = date("m/d/y - h:ia");

but how can I add 12 hours to it?

Thanks,
Hal

coopster

10:27 pm on Dec 14, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The second argument to the date() function is a unix timestamp. You could use other functions such as mktime() [php.net] or strtotime() [php.net] to add 12 hours to the current timestamp and use that as your second argument.

hal12b

10:53 pm on Dec 14, 2008 (gmt 0)

10+ Year Member



coopster - could you provide me a sample code? I am only a novice right now with PHP. Thanks

coopster

10:59 pm on Dec 14, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



print date("m/d/y - h:ia") . "\n"; 
print date("m/d/y - h:ia", strtotime('+12 hours'));

hal12b

1:33 am on Dec 15, 2008 (gmt 0)

10+ Year Member



thanks coop!