$today = date("Ymd");
if($input_date > $today)
{ echo "Date must be before today!"; }

It looks like you're dealing with MySQL dates. There are a ton of useful
functions you can use in your queries that make any time manipulation in
PHP unnecessary. Chapter 6, Date and Time Functions of the MySQL manual.

---John Holmes...

> -----Original Message-----
> From: Timothy J. Luoma [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, June 30, 2002 10:31 PM
> To: PHP Mailing List
> Subject: [PHP] checking date is not greater than today
> 
> 
> I am trying to compare a given date string (i.e. June 30, 2002 is
> 20020630).  I want to make sure that the input string that is given is
not
> greater than today (i.e. if today is June 30, and you ask for
20020701, I
> want to be able to throw an error).
> 
> I'm a newbie, so I'm not sure the best way to do this.  My thought was
> that if I take the year (YYYY) and add on the day-of-year (i.e. Feb 10
=
> 041) then I would be able to compare them as you would any other
numbers.
> 
> The problem I have then run into is that strftime and date seem to
have
> different opinions as to what day of the year it is.
> 
> date
>       z - day of the year; i.e. "0" to "365"
> 
> strftime
>       %j - day of the year as a decimal number (range 001 to 366)
> 
> 
> I have these variables defined
> 
>       $SEARCHYEAR = YYYY
> i.e 2002
> 
>       $SEARCHMONTH = MM
> i.e. 06
> 
>       $SEARCHDAY = DD
> i.e. 30
> 
> 
> $TODAYCMP=date ("Yz");
> 
>
$SEARCHCMP=strftime("%Y%j",mktime(0,0,0,$SEARCHMONTH,$SEARCHDAY,$SEARCHY
EA
> R));
> 
> and then I tried it for today and got
> 
>       echo "<!-- TODAY is $TODAYCMP SEARCHCMP is $SEARCHCMP --> ";
> 
> as a result I get
> 
> <!-- TODAY is 2002180 SEARCHCMP is 2002181 -->
> 
> 
> So I'm trying to figure out:
> 
> A) Why strftime and date don't handle leap years the same way
> 
> and (more importantly)
> 
> B) The best way to make sure a given date YYYYMMDD is not greater than
>       "today"
> 
> I did some googling & php.net searching without luck.
> 
> Thanks
> TjL
> 
> 
> 
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to