0

I have an SQL table with a field "time_created" in the form "Wed, 19 Aug 2015 03:58:00 -0600". I need to check this field against today and perform a where statement according to it, as in

SELECT * FROM table WHERE UNIX_TIMESTAMP() - UNIX_TIMESTAMP(time_created) >= 3600*24*30

to select records where time_created is older then a month.

Problem is UNIX_TIMESTAMP doesn't understand formats as "Wed, 19 Aug 2015 03:58:00 -0600". Any other way?

3
  • What is the data type of the column? Commented Sep 13, 2015 at 15:00
  • Do you mean that it isn't an actual date but just a text in English? What role does PHP play in the question? Commented Sep 13, 2015 at 15:33
  • it's a varchar column created by a php script Commented Sep 14, 2015 at 12:59

1 Answer 1

1

Try:

SELECT *
FROM table 
WHERE DATE(NOW()) > DATE_SUB(STR_TO_DATE(time_created, '%a, %e %b %Y %T'), INTERVAL 1 MONTH)

This will find all records where the current date (DATE(NOW())) is bigger than time_created subtract ` month.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks. Just a small change. It works with > DATE_ADD

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.