473,378 Members | 1,377 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,378 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 2331
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.