how to find number of days(days ago)different between today and database date ..
eg: difference between 04/09/2014 and 06/08/2014 =(no of days ago)
^^ That will not do what you want. It doesn't even extract data from pre-formatted dates so that they can be used with mktime()
.
To date: 5 posts with 5 links to your site. What are the chances of you reaching 10 posts and 10 links, I wonder?
You can try
$endDate='2014-04-11';
$startdate='2014-04-01';
$daydiff = floor( ( strtotime( $endDate ) - strtotime( $startdate ) ) / 86400);
echo $daydiff;
it will count the day difference between the 2 dates
^^ No it won't. Try running this on around the time of daylight saving or on a leap year and it will fail.
$endDate='2014-04-11';
$startdate='2014-03-31';
$daydiff = floor( ( strtotime( $endDate ) - strtotime( $startdate ) ) / 86400);
echo $daydiff;
$endDate='2014-04-11';
$startdate='2014-03-30';
$daydiff = floor( ( strtotime( $endDate ) - strtotime( $startdate ) ) / 86400);
echo $daydiff;
This will give you the same number of days on Europe/London Timezone due to the clocks going forward an hour on March 30.
Never use this to calculate differences.
I will refer you to the official link once again:
Hi Sorry about that its just that i am using it here in philippines and have no problem when it comes to leaf year or daylight. anyway base on the manual.
date_default_timezone_set('Asia/Manila');
$startdate=date_create("2014-03-30");
$endDate=date_create("2014-04-02");
$diff=date_diff($startdate,$endDate);
echo $diff->format("%a");
Yep, that's the procedural version. Should do. However I remember a problem with running this on Windows a while back. I think it was to do with %a
- I sort of remember you had to have PHP VC9 instead of VC6 installed. I may be wrong - it was a while ago.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.