Jump to content

select records within a date range


otuatail

Recommended Posts

Hi this is a dificult one for me. I want to select records from the last 3 days. ie

select * from table where Date > '2010-05-24 00:00:00' and Date < '2010-05-27 23:59:59'

 

I can get todays date and add 23:59:59. The problem is subtracting three days. is there any mysql function that can be used for the first date (today - 3 days)

 

Desmond.

 

Link to comment
https://forums.phpfreaks.com/topic/203086-select-records-within-a-date-range/
Share on other sites

Ok I think I have nearly solved this.

This works

SELECT * 
FROM WorldCup
WHERE Date > DATE_ADD( CURDATE( ) , INTERVAL 15 
DAY ) 
AND Date < DATE_ADD( CURDATE( ) , INTERVAL 16 
DAY ) 

This dosn't

SELECT * 
FROM WorldCup
WHERE Date > DATE_ADD( CURDATE( ) +'00:00:00', INTERVAL 15 
DAY ) 
AND Date < DATE_ADD( CURDATE( ) + '23:59:59', INTERVAL 15 
DAY ) 

How do I get the hours into it as it will default to midnight.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.