0

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)

4
Contributors
7
Replies
33
Views
3 Years
Discussion Span
Last Post by diafol
0

^^ 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?

Edited by diafol

-1

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

Edited by ehpratah: changes

0

^^ 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:

http://www.php.net/manual/en/datetime.diff.php

Edited by diafol

0

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");
0

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.

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.