Jump to content

finding difference between current date and future date.


cloudll

Recommended Posts

Hey,

 

I have been trying to tweak this code to tell me the days between the current date and a future date. The snippet below however sets a start date rather than using the current date.

I have been trying to format date() in a way that will work but have had no luck.

$date1=date_create("2013-03-15");
$date2=date_create("2013-12-12");
$diff=date_diff($date1,$date2);
echo $diff->format("%R%a days");

Could someone tell me what I need to do to get it working please? Thank you.

Use the datetime object, and this is pretty simple.

 

 

$date1 = new DateTime();
$date2 = date_create("2013-12-12");
$diff = date_diff($date1,$date2, true);
echo $diff->format("%R%a days");

 

This works well to work out the difference :) Thanks. However I cant seem to echo $date1. Is this normal with datetime?

 

EDIT: Figured it out, my silly mistake

Archived

This topic is now archived and is closed to further replies.

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