简体   繁体   中英

Get a date range in 24 hour format in mysql

I want to know is this query part is correct or not:

DATE_FORMAT(@co, '%Y-%m-%d %T') between '2014-03-24 13:00:00' and '2014-03-25 00:00:00'

because I'm getting wrong output from this query. Can anyone can tell what is wrong with it ?

Here @co is a string value which I want to convert as a 24hr date format.

Whether results are correct depend on what @co contains. But, as its name suggests, DATE_FORMAT() expects a date , not a string.

You should note that MySQL can handle dates as any other data type—you don't need to convert them to strings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM