Jump to content

[SOLVED] How to calculate date difference???


joshi_v

Recommended Posts

Do you want somethink like that ? ? ?

 

 

<?php

 

$date1 = date("Y");

$date2 = date("Y")+11;

$deference;

 

if($date1 > $date2)

{

$deference = ($date1 - $date2);

}

else

{

$deference = ($date2 - $date1);

}

 

if($deference <= 5)

{

echo "It's ok";

}

else

{

echo "It's to much";

}

 

?>

Thanks for reply!

 

This code will check only year part. i have to got check the whole date.

 

Example:

 

Current Date : 20070328   (ymd)

The date i have to check is  20020327

 

Differnce between these 2 days id  5 years 1 day.

 

With this result i want to check it is greater than 5 years or not.

 

Hope i could explain better..

the deference must be less that 5 years and 1 day ? ? ? ?

 

For example

 

1/1/1900 1/1/1905 is correct  (format [ day / month / year ])

1/1/1900 2/1/1905 is incorrect (format [ day / month / year ])

 

Tell me to know about . . .

Because i can't catch what you realy need try this code

 

<?php

$datestamp1 = 20070328;

$datestamp2 = 20020327;

 

$d1_day = idate("d", $datestamp1);      // Day

$d1_mon = idate("m", $datestamp1);    // Month

$d1_yea = idate("Y", $datestamp1);      // Year

$d1_hou = idate("H", $datestamp1);      // Hour

$d1_min = idate("i", $datestamp1);        // Minutes

$d1_sec = idate("s", $datestamp1);      // Seconds

 

$d2_day = idate("d", $datestamp2);      // Day

$d2_mon = idate("m", $datestamp2);    // Month

$d2_yea = idate("Y", $datestamp2);      // Year

$d2_hou = idate("H", $datestamp2);      // Hour

$d2_min = idate("i", $datestamp2);        // Minutes

$d2_sec = idate("s", $datestamp2);      // Seconds

 

echo $d1_day . "/" . $d1_mon . "/" . $d1_yea . " - - " . $d1_hou . ":" . $d1_min . ":" . $d1_sec;

echo "<br />";

echo $d2_day . "/" . $d2_mon . "/" . $d2_yea . " - - " . $d2_hou . ":" . $d2_min . ":" . $d2_sec;

 

?>

 

and make tha changes as you want . . .

 

Kind regards

 

Nikos . . .

 

Thank u all guys for your valuable suggestions!

 

I could do this in my own way atlast!

 

Actually what i am trying to do is, checking the given date should be in the time span of 5 years from the current date. The difference between the current date and the given date should be less than 5 years!

 

Here is my code for it.

 

function check_date($paramDate) (Y-m-d) Format.

{

$today_date=date('Y-m-d'); #Current Date.

 

$temp_year=substr($today_date,0,4)-5; # Subtract 5 years the from the current year.

 

$compare_with=$temp_year.'-'.substr($today_date,5,2).'-'.substr($today_date,8,2); # Form another date with the previous year. 5years back date for today's date.

 

if(strtotime($paramDate)<strtotime($compare_with))

{

return false;

}

else

{

return true;

}

}

 

Once Again thank u Nikos and Jitesh for spending u r valuable time on this.

 

 

Have a great Day!!

 

Joshi.

 

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.