468,505 Members | 1,686 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

Can using the date cause problems for date comparison?

JJ
Here's the code.

$link="http://xbox360cheat.org";

$close_date=$_POST["close_date"]; #last content change check

if ($close_date == 0)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date
("d")+7, date("Y")));
else if ($close_date == 1)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date
("d")+5, date("Y")));
else if ($close_date == 2)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date
("d")+3, date("Y")));
else if ($close_date == 3)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date
("d")+14, date("Y")));
else if ($close_date == 4)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date
("d")+21, date("Y")));
else if ($close_date == 5)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m")+1, date
("d"), date("Y")));
else if ($close_date == 6)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m")+2, date
("d"), date("Y")));
else if ($close_date == 7)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m")+3, date
("d"), date("Y")));

$linkStatus=checkDate($link,$close_date);

Could the close_date be one that is not the expected value? For example,
if the month is 11 and $close_date == 7, then the mktime function should
return the next year for the year value, not the current year. And if the
day is the last week of December, than the month and year should change
if close_date == 7. Thanks for any help.

May 12 '07 #1
3 2096
On May 11, 9:13 pm, JJ <j...@aol.comwrote:
Here's the code.

$link="http://xbox360cheat.org";

$close_date=$_POST["close_date"]; #last content change check

if ($close_date == 0)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date
("d")+7, date("Y")));
else if ($close_date == 1)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date
("d")+5, date("Y")));
else if ($close_date == 2)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date
("d")+3, date("Y")));
else if ($close_date == 3)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date
("d")+14, date("Y")));
else if ($close_date == 4)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date
("d")+21, date("Y")));
else if ($close_date == 5)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m")+1, date
("d"), date("Y")));
else if ($close_date == 6)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m")+2, date
("d"), date("Y")));
else if ($close_date == 7)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m")+3, date
("d"), date("Y")));

$linkStatus=checkDate($link,$close_date);

Could the close_date be one that is not the expected value? For example,
if the month is 11 and $close_date == 7, then the mktime function should
return the next year for the year value, not the current year. And if the
day is the last week of December, than the month and year should change
if close_date == 7. Thanks for any help.
According to the manual, mktime() will return false if the arguments
are invalid.

You can avoid such problems altogether by just using strtotime(). It
also makes what you're trying to do clearer:

switch($close_date) {
case 0:
$close_date = strtotime('+7 days');
break;
case 1:
$close_date = strtotime('+5 days');
break;
case 2:
$close_date = strtotime('+3 days');
break;
case 3:
$close_date = strtotime('+2 weeks');
break;
case 4:
$close_date = strtotime('+3 weeks');
break;
case 5:
$close_date = strtotime('+1 month');
break;
case 6:
$close_date = strtotime('+2 months');
break;
case 7:
$close_date = strtotime('+3 months');
break;
}

//Make it noon on that day:
$close_date = mktime(12, 0, 0, date('m', $close_date), date('d',
$close_date), date('Y', $close_date));
//Format it:
$close_date = date('Y-m-d H:m:s', $close_date);

May 12 '07 #2
JJ
Great! Thanks so much.
May 12 '07 #3
At Fri, 11 May 2007 18:31:49 -0700, ZeldorBlat let his monkeys type:
On May 11, 9:13 pm, JJ <j...@aol.comwrote:
>Here's the code.

$link="http://xbox360cheat.org";

$close_date=$_POST["close_date"]; #last content change check

if ($close_date == 0)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date
("d")+7, date("Y")));
else if ($close_date == 1)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date
("d")+5, date("Y")));
else if ($close_date == 2)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date
("d")+3, date("Y")));
else if ($close_date == 3)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date
("d")+14, date("Y")));
else if ($close_date == 4)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date
("d")+21, date("Y")));
else if ($close_date == 5)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m")+1, date
("d"), date("Y")));
else if ($close_date == 6)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m")+2, date
("d"), date("Y")));
else if ($close_date == 7)
$close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m")+3, date
("d"), date("Y")));

$linkStatus=checkDate($link,$close_date);

Could the close_date be one that is not the expected value? For example,
if the month is 11 and $close_date == 7, then the mktime function should
return the next year for the year value, not the current year. And if the
day is the last week of December, than the month and year should change
if close_date == 7. Thanks for any help.

According to the manual, mktime() will return false if the arguments
are invalid.

You can avoid such problems altogether by just using strtotime(). It
also makes what you're trying to do clearer:

switch($close_date) {
case 0:
$close_date = strtotime('+7 days');
break;
case 1:
$close_date = strtotime('+5 days');
break;
case 2:
$close_date = strtotime('+3 days');
break;
case 3:
$close_date = strtotime('+2 weeks');
break;
case 4:
$close_date = strtotime('+3 weeks');
break;
case 5:
$close_date = strtotime('+1 month');
break;
case 6:
$close_date = strtotime('+2 months');
break;
case 7:
$close_date = strtotime('+3 months');
break;
}

//Make it noon on that day:
$close_date = mktime(12, 0, 0, date('m', $close_date), date('d',
$close_date), date('Y', $close_date));
//Format it:
$close_date = date('Y-m-d H:m:s', $close_date);
Admittedly, this is very legible and correct.
Less obvious but short:

$dateopts=array('+7 days','+5 days','+3 days','+2 weeks',
'+3 weeks','+1 month','+2 months','+3 months');
$close_date= strtotime ($dateopts[$close_date]);

Sh.

May 12 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Lloyd Sheen | last post: by
1 post views Thread by sylvian stone | last post: by
5 posts views Thread by Corky | last post: by
4 posts views Thread by junkmate | last post: by
16 posts views Thread by W. eWatson | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.