tags:

views:

588

answers:

5

Hello,

How to find number of days between two dates using php.

for this i have test the answer of:

Calculate number of days between two dates in PHP [closed] (3)

on this forum.

but it does not work.

can any one help me.

A: 

If you have the times in seconds (I.E. unix time stamp) , then you can simply subtract the times and divide by 86400 (seconds per day)

zipcodeman
+7  A: 

Convert your dates to unix timestamps, then substract one from the another. That will give you the difference in seconds, which you divide by 86400 (amount of seconds in a day) to give you an approximate amount of days in that range.

If your dates are in format 25.1.2010, 01/25/2010 or 2010-01-25, you can use the strtotime function:

$start = strtotime('2010-01-25');
$end = strtotime('2010-02-20');

$days_between = ceil(abs($end - $start) / 86400);

Using ceil rounds the amount of days up to the next full day. Use floor instead if you want to get the amount of full days between those two dates.

If your dates are already in unix timestamp format, you can skip the converting and just do the $days_between part. For more exotic date formats, you might have to do some custom parsing to get it right.

Tatu Ulmanen
+1 for examples.
zipcodeman
+2  A: 
<?php

$now = time(); // or your date as well
$your_date = strtotime("2010-01-01");
$datediff = $now - $your_date;
echo floor($dateDiff/(60*60*24));

?>
Adnan
+1  A: 

Ues it :)

$days = (strtotime($endDate) - strtotime($startDate)) / (60 * 60 * 24);
print $days;

Now its oKKKK

Muhammad Sajid
Now accept an answer.
zipcodeman
Muhammad, this is not a forum. You shouldn't post answers to your own question unless someone else was unable to answer it for you, which is not the case in this situation. You'll want to make use of the comment feature to get clarification on individual answers. Also, you can always edit your original question.
Justin Johnson