Forum Moderators: coopster

Message Too Old, No Replies

Using the mysql now() func

select records that are now()+3 days

         

d40sithui

11:26 am on Jul 30, 2007 (gmt 0)

10+ Year Member



so i have a table with a date column. i have scripts that wuold insert now() into that column whenever processed. so the format would be yyyy-mm-dd in the table.
does anyone know how form a query to select the records with the (date column + x days) to it?

omoutop

11:48 am on Jul 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



not sure, but you may try the BETWEEN suntax

"select * from table where date_field between x and y",
where x,y your date ranges.

I guess there must be another more convinient way

distorto

2:35 pm on Jul 30, 2007 (gmt 0)

10+ Year Member



I don't know if this will help, but here's a sql statement that deletes rows from a collumn called 'messages' where the 'date' is more than one day ago.

DELETE FROM `messages` WHERE date < NOW() - INTERVAL 1 DAY

ps - I had troubles with these until I set the mysql data type for 'date' to timestamp. That's what NOW() produces.

d40sithui

5:48 pm on Jul 30, 2007 (gmt 0)

10+ Year Member



yea i tried that, it does work but um, i need something for 3 days. I guess i can use the strtotime() function, convert now() and whatever's in the db into numbers that i can work with..but thatll a few more queries, assuming it works. =/

distorto

5:55 pm on Jul 30, 2007 (gmt 0)

10+ Year Member



INTERVAL 3 DAY

d40sithui

5:57 pm on Jul 30, 2007 (gmt 0)

10+ Year Member



oh lol thought that was a comment

jamie

5:58 pm on Jul 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



don't know if this may be the problem, but remember to enclose the yyy-mm-dd field in the query in quotes

select * from table where date between '20007-07-01' and '20007-08-01'

that catches me out lots ;)

d40sithui

6:02 pm on Jul 30, 2007 (gmt 0)

10+ Year Member



thanks for the tips guys!