PDA

View Full Version : Limiting by dates


bauhsoj
02-14-2008, 01:48 AM
I have here what should be a no brainer, and perhaps it is the lack of sleep and the long hours today, but I need someone to confirm for me that my logic with the following is on target.

If I want to find all records that were dated either '0', or no older than (approx) 6 months in the past, then the following condition should work for that, correct?

UNIX_TIMESTAMP() - 6*30*24*60*60 > table.dated

The field 'dated' is of course a UNIX timestamp integer field.

websquid
02-20-2008, 02:11 AM
SELECT * FROM table WHERE date = 0 OR FROM_UNIXTIME( dated ) > NOW() - INTERVAL 6 MONTH;

you should really be using date fields and not storing the unix timestamp - makes life alot easier

StupidRalph
02-20-2008, 02:59 PM
I also encourage you to start using a date field. I know a lot of people don't like to use it b/c of the way it stores dates. But once, they realize all of the DATE FUNCTIONS then they quickly realize all of the advantages. Plus....its a date...storing in a date feild is semantically correct.