user630320
user630320

Reputation:

PHP MYSQL compare date time

I have a field in a table called created_at which i would to compare with two different dates.

e.g. created_at BETWEEN '2011-08-01 13:23:21' AND '2011-08-07 13:23:21'

i like to show all records which created in these two dates.

i have tried different method but still with no luck.

Upvotes: 0

Views: 3522

Answers (2)

Esteban
Esteban

Reputation: 35

SUBSTRING(now(), 1, 10) = '2015-0-15'

Upvotes: 0

Sergi Ramón
Sergi Ramón

Reputation: 1744

First be sure to set your date_field to DATETIME type, then do the query like this:

SELECT * FROM your_table WHERE date_field >= '2011-08-01 13:23:21' AND date_field <= '2011-08-07 13:23:21'

Upvotes: 4

Related Questions