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.

Link to comment
Share on other sites

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

Edited by cloudll
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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