Re: [PHP] checking date is not greater than today
On 30 Jun 2002 at 22:31, Timothy J. Luoma wrote: > > 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 () 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. [...] snipped I ignored the rest as it was beyond me. I'm also a newbie to PHP but I looked into dates in Perl. I quickly began using a module from CPAN as I realized this was more complicated than meets the eye and you seem to indcate that when you mention leap years. I would question why you accept input as a particular format. It's certainly easier to work with timestamps than arbitrary representations of dates. I would not be so quick to assume you have to accept input as is. Or at least have it fixed to a format ... but the Perl modules I've worked with are liberal with what they receive :) Anyhow, I'd just find a PHP module ot handle this. I found this: http://www.phpbuilder.com/columns/akent2610.php3 but I'd just want a class (guess you call it that in PHP). And then this looks real interesting: > Date/Time Processing with PHP > By The Disenchanted Developer > March 19, 2002 http://zope1.devshed.com/zope.devshed.com/Server_Side/PHP/DateTime/page1.html In Perl I happen to use this moduel for date manipulation: http://search.cpan.org/doc/STBEY/Date-Calc-5.0/Calc.pod There must be something similar in PHP but since I too am a newbie (and lazy to boot) I don't know what it is. Peter -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checking date is not greater than today
On Sun, 30 Jun 2002, John Holmes wrote: > $today = date("Ymd"); > if($input_date > $today) > { echo "Date must be before today!"; } *thwaps self* DUH! Thanks... been staring at this for too long. > 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. I'm not dealing with MySQL dates yet, just simple query strings, but I'll check that out before I get into MySQL. Thanks TjL -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] checking date is not greater than today
$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 () 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 = > 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 " "; > > as a result I get > > > > > 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 MMDD 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
[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 () 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 = 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,$SEARCHYEAR)); and then I tried it for today and got echo " "; as a result I get 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 MMDD 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