0

Hey all
I am doing a mini countdown type thing but i have hit a snag.
What i am first trying to do is get the time 7 days from now and then(later insert into database but not now) work out the difference between the current date and the date that was said to be in 7 days, even though it will be eg 4 days 5 hours from that date.

What i have so far is

<?php
$when = 'now';
$nextWeek = date('Y-m-d H:i:s',strtotime("$when +7 days 4 hours 2 seconds"));
echo $nextWeek;
//test data
//$nextWeek = time()+86400*7;
//echo date("Y-m-d H:i:s", $nextWeek);  

$iStartDate = 'now';
$iEndDate = $nextWeek;

printf
(
    'Distance between 2 dates is %d days.',
    (strtotime($iEndDate) - strtotime($iStartDate)) / 86400
);
?>

The problem now is that it will only pull out the amount of days, but i would also like the hours and minutes to show.

Can anyone help me please. This would very much be appreciated.

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by darkagn
0

Check out the documentation for the strftime function. What you want to do is get the current timestamp ( use time() ) and the timestamp for your time in 7 days (use strtotime() ), get their difference and then use the strftime function to get the string in the form you want.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.