Jump to content


Photo

Date1 Minus Date1


  • Please log in to reply
4 replies to this topic

#1 mvosoughi

mvosoughi
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 27 June 2006 - 10:14 PM

I have a database and I need to retrive date for last 6 months from today's date. Basically it is a 6 months rollover. I tried to subtract old date from today's date but I was unsuccessful. Any ideas? thanks..

#2 Travis Estill

Travis Estill
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 27 June 2006 - 10:50 PM

Retrieve data from the last 6 months? Assuming you're using timestamps, try this:

$query = "SELECT data FROM table WHERE time >= (".time()." - 15778463)";

Freelance Web Developer with a focus on PHP/MySQL

Angel-Stones.com
ClanQ3.com

#3 Travis Estill

Travis Estill
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 27 June 2006 - 11:37 PM

[!--quoteo(post=388668:date=Jun 27 2006, 05:47 PM:name=melv)--][div class=\'quotetop\']QUOTE(melv @ Jun 27 2006, 05:47 PM) View Post[/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:

// 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
  }

Freelance Web Developer with a focus on PHP/MySQL

Angel-Stones.com
ClanQ3.com

#4 mvosoughi

mvosoughi
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 28 June 2006 - 07:59 AM

[!--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) View Post[/div][div class=\'quotemain\'][!--quotec--]
Oh, I see. Use strtotime() like this:

// 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
  }
[/quote]


Thanks guys.. worked alright ... cheers

#5 yong

yong
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 28 June 2006 - 09:01 AM

i have a small question :

This line: "$old = time() - 15778463; /* 6 months ago */"

how calculate 15778463...

think you !




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users