Jump to content

[SOLVED] How to calculate date difference???


joshi_v

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

 

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.

 

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.