Axel Posted July 8, 2013 Share Posted July 8, 2013 Hi all, Hopefully a quick one. I want to select rows where the date is 1 days prior to the current day. Trouble is the date is stored in a UK format as text (i.e. 17/06/2013). Is this possible? so far I have this which obviously wont work: SELECT * FROM surveys WHERE date < CURRENT_TIMESTAMP - INTERVAL 1 DAY Any ideas? Many thanks. Alex Link to comment Share on other sites More sharing options...
0 ILikeTobacco Posted July 8, 2013 Share Posted July 8, 2013 http://stackoverflow.com/questions/12831791/whats-the-sql-function-for-timestamp-manipulation Link to comment Share on other sites More sharing options...
0 Axel Posted July 8, 2013 Author Share Posted July 8, 2013 Sorry I'm not sure I understand that. My knowledge in this area is still a little young. Link to comment Share on other sites More sharing options...
0 ILikeTobacco Posted July 8, 2013 Share Posted July 8, 2013 Sorry I'm not sure I understand that. My knowledge in this area is still a little young. Take the current timestamp, convert it to the same format as what is in the database, then run your query using that. Link to comment Share on other sites More sharing options...
0 Axel Posted July 9, 2013 Author Share Posted July 9, 2013 As much as I could do that easily using PHP, I'm not sure where to start with a MySQL query string?? Link to comment Share on other sites More sharing options...
0 Kami- Posted July 9, 2013 Share Posted July 9, 2013 SELECT * FROM surveys WHERE date < (DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY)) May not be 100% accurate as it's typed direct into browser from memory; but should be fairly near the mark. (Note if you plan on including the previous day, you should use <= ;)) Link to comment Share on other sites More sharing options...
0 Haggis Veteran Posted July 9, 2013 Veteran Share Posted July 9, 2013 would it not just be = if your using interval of 1 day so like this? SELECT * from surveys where date = DATE_SUB(CURRENT_DATE(),INTERVAL 1 DAY); Link to comment Share on other sites More sharing options...
0 Axel Posted July 9, 2013 Author Share Posted July 9, 2013 Thats brilliant thanks! Is it possible to take a text field and treat it like a date? i.e. the above works on a properly formatted column. If the date was stored as text in UK format (dd/mm/yyyy) could one do some sort of manipulation so it was read as a date in the proper format (yyyy/mm/dd). I know this can be done in php, I wonder if it would work in a mySQL query though? Link to comment Share on other sites More sharing options...
0 Kami- Posted July 9, 2013 Share Posted July 9, 2013 Thats brilliant thanks! Is it possible to take a text field and treat it like a date? i.e. the above works on a properly formatted column. If the date was stored as text in UK format (dd/mm/yyyy) could one do some sort of manipulation so it was read as a date in the proper format (yyyy/mm/dd). I know this can be done in php, I wonder if it would work in a mySQL query though? Err... DATE_FORMAT(date,'%Y/%m/%d') Link to comment Share on other sites More sharing options...
Question
Axel
Hi all,
Hopefully a quick one. I want to select rows where the date is 1 days prior to the current day.
Trouble is the date is stored in a UK format as text (i.e. 17/06/2013). Is this possible?
so far I have this which obviously wont work:
Any ideas?
Many thanks.
Alex
Link to comment
Share on other sites
8 answers to this question
Recommended Posts