|
|
|
|
Thread title: Comparing dates |
|
|
|
|
|
Thread tools
Search this thread
Display Modes
|
|
03-18-2007, 07:00 PM
|
#1
|
Status: Junior Member
Join date: Oct 2005
Location:
Expertise:
Software:
Posts: 38
|
Comparing dates
Hello,
I made a todo list script for the users that use my site. The only problem is im not sure how to compare the current date and the finish date of the todo item, obviously, with 2 factors, if the todo item is within 7 days of becoming overdue show a message, if it is overdue show a message, if its fine, dont do anything, can anyone help me with this?
Thanks in advanced,
Andy
|
|
03-18-2007, 07:06 PM
|
#2
|
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
Posts: 5,200
|
You can use simple math such as:
PHP Code:
echo date()+7*24*60*60; // SHOULD ouput a date 7 days from now
I think that's what it is..
|
|
03-18-2007, 08:58 PM
|
#3
|
Status: Junior Member
Join date: Oct 2005
Location:
Expertise:
Software:
Posts: 38
|
yeh but i already have the "future" date, i just need to compare to the current date and have a 7 days difference like i stated..
|
|
03-18-2007, 09:24 PM
|
#4
|
Status: Superstar
Join date: Apr 2005
Location:
Expertise:
Software:
Posts: 4,449
|
Then do something like:
PHP Code:
<? $date = date()+7*24*60*60; if ($futuredate == $date){ print "Woohoo, it does equal seven days from now!"; }else{ print "That's different than 7 days from now!"; } ?>
|
|
03-18-2007, 09:25 PM
|
#5
|
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
Posts: 6,894
|
to find if it is larger, smaller or equel, just use >, <, or ==, respectively. php can manage dates just like numbers.
|
|
03-18-2007, 11:25 PM
|
#6
|
Status: Member
Join date: Oct 2005
Location: Clifton Park, NY, USA
Expertise:
Software:
Posts: 273
|
I haven't put this into a script or anything, but wouldn't you have to use mktime(), instead of date(). As date returns the string of the date, not the ms since 1970.
Mubs
|
|
03-18-2007, 11:37 PM
|
#7
|
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
Posts: 5,200
|
mktime() is just more typing in my opinion. It's not much harder to do date.
|
|
03-19-2007, 04:31 PM
|
#8
|
Status: Junior Member
Join date: Oct 2005
Location:
Expertise:
Software:
Posts: 38
|
that cant be it :S, i get:
Warning: Wrong parameter count for date()
|
any ideas?
|
|
03-19-2007, 06:24 PM
|
#9
|
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
Posts: 6,894
|
If I recall its time(), not date()
PHP Code:
<?php
$nextWeek = time() + (7 * 24 * 60 * 60);
//$nextWeek is something along the lines of 1174934333, you need date() to format it
//unless you users can read unix timestamps ;-)
echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n";
?>
The first param is the format it should output, the second is the timestamp (data) it will take it from. If left blank it gets the current time from the server.
http://www.php.net/time for more info
For your purposes, you should be able to use mathematical operators to compare.
|
|
|
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|