Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1586 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Comparing dates

Thread title: Comparing dates
Closed Thread    
    Thread tools Search this thread Display Modes  
03-18-2007, 07:00 PM
#1
WinSrev is offline WinSrev
WinSrev's Avatar
Status: Junior Member
Join date: Oct 2005
Location:
Expertise:
Software:
 
Posts: 38
iTrader: 0 / 0%
 

WinSrev is on a distinguished road

  Old  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
Andrew R is offline Andrew R
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
 
Posts: 5,200
iTrader: 17 / 95%
 

Andrew R is on a distinguished road

  Old

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
WinSrev is offline WinSrev
WinSrev's Avatar
Status: Junior Member
Join date: Oct 2005
Location:
Expertise:
Software:
 
Posts: 38
iTrader: 0 / 0%
 

WinSrev is on a distinguished road

  Old

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
Jeff Andersen is offline Jeff Andersen
Status: Superstar
Join date: Apr 2005
Location:
Expertise:
Software:
 
Posts: 4,449
iTrader: 10 / 100%
 

Jeff Andersen is on a distinguished road

  Old

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
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

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
iisbum is offline iisbum
iisbum's Avatar
Status: Member
Join date: Oct 2005
Location: Clifton Park, NY, USA
Expertise:
Software:
 
Posts: 273
iTrader: 4 / 100%
 

iisbum is on a distinguished road

  Old

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
Andrew R is offline Andrew R
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
 
Posts: 5,200
iTrader: 17 / 95%
 

Andrew R is on a distinguished road

  Old

mktime() is just more typing in my opinion. It's not much harder to do date.

03-19-2007, 04:31 PM
#8
WinSrev is offline WinSrev
WinSrev's Avatar
Status: Junior Member
Join date: Oct 2005
Location:
Expertise:
Software:
 
Posts: 38
iTrader: 0 / 0%
 

WinSrev is on a distinguished road

  Old

that cant be it :S, i get:

Warning: Wrong parameter count for date()
any ideas?

03-19-2007, 06:24 PM
#9
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

If I recall its time(), not date()
PHP Code:
<?php
$nextWeek 
time() + (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.

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed