By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,723 Members | 1,891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,723 IT Pros & Developers. It's quick & easy.

Can using the date cause problems for date comparison?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
JJ
Great! Thanks so much.
May 12 '07 #3

P: n/a
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.