Jump to content

Date1 Minus Date1


mvosoughi

Recommended Posts

[!--quoteo(post=388668:date=Jun 27 2006, 05:47 PM:name=melv)--][div class=\'quotetop\']QUOTE(melv @ Jun 27 2006, 05:47 PM) [snapback]388668[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I need to compare dates. But this way:

I get a date from database. (yyyy-mm-dd format)

I need to understand if this date is newer then "6 months" or not.

What I need is get the current date,
calculate the date 6 months ago,
compare "the date from DB" & "the date 6 months ago from now"
show the result.

How will I do that please?
[/quote]

Oh, I see. Use strtotime() like this:

[code]// Example date
$date = "2006-06-04";

$time = strtotime($date);
$old = time() - 15778463; /* 6 months ago */
if ($time <= $old)
  {
  // Date is at least 6 months old
  }
else if ($time > $old)
  {
  // Date is less than 6 months old
  }[/code]
Link to comment
https://forums.phpfreaks.com/topic/13057-date1-minus-date1/#findComment-50254
Share on other sites

[!--quoteo(post=388674:date=Jun 28 2006, 12:37 AM:name=Travis Estill)--][div class=\'quotetop\']QUOTE(Travis Estill @ Jun 28 2006, 12:37 AM) [snapback]388674[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Oh, I see. Use strtotime() like this:

[code]// Example date
$date = "2006-06-04";

$time = strtotime($date);
$old = time() - 15778463; /* 6 months ago */
if ($time <= $old)
  {
  // Date is at least 6 months old
  }
else if ($time > $old)
  {
  // Date is less than 6 months old
  }[/code]
[/quote]


Thanks guys.. worked alright ... cheers
Link to comment
https://forums.phpfreaks.com/topic/13057-date1-minus-date1/#findComment-50331
Share on other sites

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.