Re: [PHP] Working with Dates
Robert Sossomon wrote: I have this code below that needs to display stuff depending on WHEN it is. I am pretty sure it is something simple I have confused (again) but can't place my finger on it. Anyone see the mistake? ?php $today = date(m-d-y); $early = date(m-d-y,mktime(0, 0, 0, 1, 14, 2005)); $normal = date(m-d-y,mktime(0, 0, 0, 1, 31, 2005)); if ($today = $early) //also done with writing in 01-14-05 { print trtdPre-Conference/tdtd$12/tdtdinput name=\Pre-Conference\ type=\radio\ value=\Y\/td/tr; print trtdEarly Registration (thru 01-14-05)/tdtd$85input name=\Conference\ type=\radio\ value=\Early Registration\/td/tr; print trtdRegistration for Saturday Only (thru 01-14-05)/tdtd$65/tdtdinput name=\Conference\ type=\radio\ value=\Early Saturday Only\/td/tr; } else if ($today = 01-15-05 || $today = 01-31-05) Make this be elseif (one word) or you'll some day confuse yourself when you get nested if/else things going. Also, you don't want || here, really... You'd want to say what you are trying to say. Dates *WAY* in the future are bigger then 01-15-05, and so they never get compared to 01-31-05 because you used ||. At this point, you already *KNOW* that the date is larger than 01-14-05, so the whole check about 01-15-05 is kinda pointless. elseif ($today = 01-31-05) { A couple other notes. If you're going to print() out more than a couple lines, just get out of PHP. It's going to be easier to maintain your HTML if you do. Also, you might find this a more natural way to do things: $today = time(); ?php if ($today = mktime(0, 0, 0, 1, 14, 2005){ ? Early Registration Stuff Here. ?php } elseif ($today = mktime(0, 0, 0, 1, 31, 2005){ ? Normal Registratoin Stuff Here. ?php } else{ ? Tell them how great the event was here, and how they should get on the mailing list to sign up for next year! ?php } -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Working with dates
Brad Harriger wrote: I have two variables, $StartDate and EndDate that contain values read from MySQL Date fields. How can I determine if a value entered by the user is between the two dates? I'm using PHP 4.0.6. if ($user_input $StartDate $user_input $EndDate) { // do something } Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Working with dates
I have two variables, $StartDate and EndDate that contain values read from MySQL Date fields. How can I determine if a value entered by the user is between the two dates? I'm using PHP 4.0.6. I think you can take MySQL timestamps directly into strtotime(). If($user strtotime($StartDate) $user strtotime($EndDate)) { do something; } Many ways to do it... ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Working with dates
Switch to postgres! then you can do SELECT stamp FROM table WHERE stamp BETWEEN timestamp 'today' AND timestamp 'tomorrow'; On March 17, 2003 12:43 pm, Brad Harriger wrote: I have two variables, $StartDate and EndDate that contain values read from MySQL Date fields. How can I determine if a value entered by the user is between the two dates? I'm using PHP 4.0.6. Thanks in advance, Brad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Working with dates
you do that same query in mysql Jim - Original Message - From: Joshua Moore-Oliva [EMAIL PROTECTED] To: Brad Harriger [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Monday, March 17, 2003 10:49 AM Subject: Re: [PHP] Working with dates Switch to postgres! then you can do SELECT stamp FROM table WHERE stamp BETWEEN timestamp 'today' AND timestamp 'tomorrow'; On March 17, 2003 12:43 pm, Brad Harriger wrote: I have two variables, $StartDate and EndDate that contain values read from MySQL Date fields. How can I determine if a value entered by the user is between the two dates? I'm using PHP 4.0.6. Thanks in advance, Brad -- 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
Re: [PHP] Working with dates in PHP
Hi, Friday, October 11, 2002, 3:53:55 PM, you wrote: JP I am at my wits end at the moment. I am pulling a datetimestamp out of a JP database and attempting to get the year month and day out of it. However JP I am stumped as how to do it. JP The format is -MM-DD HH:MM:SS and its coming out of a mySQL JP database. Is there anyway I can get the information I need out of here? JP I have tried $nday = date(d, $row[2]) and so on but all i get out of JP that is Year = 1970, Month = 01, Day = 01. JP Heres the code Im using now with getdate() JP while($row = mysql_fetch_row($fres)) JP { JP print($row[2]); JP $odate = getdate($row[2]); JP print($odate['mday'].br /); JP $oday = date(d, $odate); JP print($odate['mon'].br /); JP $omonth = date(m, $odate); JP print($odate['year'].br /); JP $oyear = date(Y, $odate); JP print($oyear.br /); JP } JP Any help would be appreciated. JP James Try this $ts = strtotime($row[2]);//get a unix timestamp $day = date(d,$ts); -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Working with dates in PHP
I am at my wits end at the moment. I am pulling a datetimestamp out of a database and attempting to get the year month and day out of it. Do it in your sql query. Check out chapter 6 of the MySQL manual for ways to manipulate dates. Eg. $query = select DATE_FORMAT(DTStamp, '%e %b %y') AS DispDate WHERE some=condition; Will get you a date as day month year. There's heaps of options and you should probably read up on them. CYA, Dave -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php