Re: [PHP] If date is greater than

2013-10-20 Thread Ashley Sheridan
On Sun, 2013-10-20 at 00:00 -0400, Bastien wrote:

 
 Thanks,
 
 Bastien
 
  On Oct 19, 2013, at 10:44 PM, John Taylor-Johnston 
  jt.johns...@usherbrooke.ca wrote:
  
  I have date strings in my mysql db. -mm-dd.
  I want to parse to see if the date is greater than november 2011 and less 
  than december 2012.
  
  Is this the right approach? How bad is my syntax?
  
  |function dates_range($todaynow)
  { |
  |$date1=strtotime(2011-11-01);
  $date2=strtotime(2012-12-31);
if (|||($|todaynow |= $date1) and |($|||todaynow| = 
  $date2)||)
  ||   {
  ||   # do something
     }
  }
  |||
 
 Easiest to convert to integers and then compare


Yes, I was going to ask, why are you storing your dates as strings?
MySQL has a perfectly good DATE type. It's also generally faster
comparing dates within a MySQL query than PHP code.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] If date is greater than

2013-10-20 Thread Tedd Sperling

On Oct 20, 2013, at 4:01 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote:

 Yes, I was going to ask, why are you storing your dates as strings?
 MySQL has a perfectly good DATE type. It's also generally faster
 comparing dates within a MySQL query than PHP code.
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk

Agreed.

Plus, there are many date functions provided by MySQL that are easier 
(possibility faster) than what you can do in PHP.

Check these out:

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date

tedd

___
tedd sperling
tedd.sperl...@gmail.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php