3 Replies - 360 Views - Last Post: 16 June 2012 - 03:45 AM Rate Topic: -----

#1 GolfyMcG  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 14
  • Joined: 22-November 11

Simple Date Comparison Question

Posted 16 June 2012 - 02:52 AM

Maybe I'm just tired but for some reason I cannot understand why this isn't returning the true statement.

$start_date = '2012-06-16';
$end_date = '2012-09-01';

$min_length = strtotime('+10 weeks');
$min_end_date = date('$start_date', $min_length);

$max_length = strtotime('+15 weeks');
$max_end_date = date('$start_date', $max_length);

echo "Start date: $start_date <br />";
echo "End date: $end_date <br />";
echo "Min Length: $min_end_date <br />";
echo "Max Length: $max_end_date <br />";

if($end_date>$min_end_date&&$end_date<$max_end_date)
	echo "You're good!";
else
	echo "You are not good!";



Sorry if this is a stupid question but I've been looking and I'm convinced it's right. I run it and the min/max length values are what they should be, but the conditional statement does not return what I think it should.

Thanks in advance.

Also, sorry if it wasn't obvious...

I'm trying to determine if two dates that are input (the start and end dates) are no further apart then 15 weeks (max length) but no less then 10 weeks apart (min length)

Is This A Good Question/Topic? 0
  • +

Replies To: Simple Date Comparison Question

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6091
  • View blog
  • Posts: 23,605
  • Joined: 23-August 08

Re: Simple Date Comparison Question

Posted 16 June 2012 - 03:31 AM

Start by carefully reading the documentation on date(). Note the first argument to the function....is it an actual date, or something else entirely?
Was This Post Helpful? 0
  • +
  • -

#3 GolfyMcG  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 14
  • Joined: 22-November 11

Re: Simple Date Comparison Question

Posted 16 June 2012 - 03:33 AM

OOOOOOOOOOOOHHHHHHHHHHHHHHHHHHHHH

...

Ugh. Thanks, I'll rework it another way lol...
Was This Post Helpful? 0
  • +
  • -

#4 GolfyMcG  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 14
  • Joined: 22-November 11

Re: Simple Date Comparison Question

Posted 16 June 2012 - 03:45 AM

For anyone who hoped to know the solution (despite it being pretty easy...)

$start_date = strtotime('2012-06-16');
$end_date = strtotime('2012-09-16');

$min_length = strtotime('+10 weeks',$start_date);
$max_length = strtotime('+15 weeks',$start_date);

echo "Start date: $start_date <br />";
echo "End date: $end_date <br />";
echo "Min Length: $min_length <br />";
echo "Max Length: $max_length <br />";

if($end_date<$max_length&&$end_date>$min_length)
	echo "You're okay!";
else
	echo "You must be between 10 and 15 weeks!";



Thanks for the help again!
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1