473,237 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,237 software developers and data experts.

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 2320
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Lloyd Sheen | last post by:
Below is the output from command window. This shows values of variables and result of comparison. Make no sense except to dot.net. Any ideas?? ?pofile #11/11/2003 12:39:22 PM# ?pdtdbdate
1
by: sylvian stone | last post by:
Hi, I've used standard date functions in the past, but need to create something a little different, as I am working on an investment calculator. What I need to do is validate two dates, and...
5
by: Corky | last post by:
This works: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS INNER JOIN PROBLEMS ON PROBLEM_OBJECTS.PROBLEM_ID = PROBLEMS.PROBLEM_ID WHERE INTEGER(DAYS(CURRENT DATE) -...
11
by: Bobbak | last post by:
Hello All, I have these tables (lets call it ‘EmpCalls', ‘EmpOrders', and ‘Stats') that each contain the list of EmployeeIDs, I want to be able to create a Module in which I could call in my VB...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
6
by: sales | last post by:
Hello, I am trying to get my website checkout page to rotate / take turns displaying shopping comparison engine surveys rather than display them all 4 at the same time, thus overwhelming &...
3
by: Andreas | last post by:
Hi! I'm currently developing a DLL that makes use of C++ and .net (mixed) using Visual Studio 2003. Now, as I wanted to move to the new Visual Studio 2005, I converted this project into the...
4
by: junkmate | last post by:
I am making an RSS parser that takes multiple XML inputs in to an array and then sorts them by their date value... and it 'almost' works... I always lose the top value of the second rss feed to be...
16
by: W. eWatson | last post by:
Are there some date and time comparison functions that would compare, say, Is 10/05/05 later than 09/22/02? (or 02/09/22 format, yy/mm/dd) Is 02/11/07 the same as 02/11/07? Is 14:05:18 after...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.