using date format instead of linux time

时间:2015-10-06 08:46:39

标签: php sql

I usually convert date to linux time so i will be able to select records between two dates.

for instance:

WHERE create_date > 1443627575 AND create_date < 1443637575

is it possible to select data using dates (without converting them to linux time)? for instance:

WHERE create_date > 20-03-2015 AND create_date < 25-03-2015

also, can I change the date format in my MySQL so it will be dd/mm/yy ?

3 个答案:

答案 0 :(得分:1)

You can select like this WHERE create_date BETWEEN '20-03-2015' AND '25-03-2015'

and Yes you can change date format in mysql calling this -

DATE_FORMAT(NOW(),'%m-%d-%Y')    

*put your date for NOW

答案 1 :(得分:1)

You can use STR_TO_DATE and BETWEEN :

WHERE create_date BETWEEN 
    STR_TO_DATE('20-03-2015', '%d-%m-%Y') and 
    STR_TO_DATE('25-03-2015', '%d-%m-%Y')

答案 2 :(得分:0)

Use the from_unixtime function.

SELECT *
FROM yourtable
WHERE from_unixtime(create_date) BETWEEN '20-03-2015' AND '25-03-2015'

//date should be with in quotes