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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.