开发者

how to work on mysql date fomat?

开发者 https://www.devze.com 2023-01-07 07:18 出处:网络
What is the problem with the mysql syntax SELECT FORMAT(dCreatedDate,\'YYYY-MM-DD\') as date1 FROM tbl_book_self

What is the problem with the mysql syntax SELECT FORMAT(dCreatedDate,'YYYY-MM-DD') as date1 FROM tbl_book_self 开发者_如何转开发I want to select the date from mysql database in this format,How to use this syntax


Did you mean to use DATE_FORMAT rather than just FORMAT?

Also the format needs to be specified using % notation so the corrected version of your example would be

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

You can find a list of the specifiers you can use in the format string in the MySQL documentation on Date and Time Functions.


mysql> SELECT DATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y');
        -> 'Sunday October 2009'
mysql> SELECT DATE_FORMAT('2007-10-04 22:23:00', '%H:%i:%s');
        -> '22:23:00'
mysql> SELECT DATE_FORMAT('1900-10-04 22:23:00',
    ->                 '%D %y %a %d %m %b %j');
        -> '4th 00 Thu 04 10 Oct 277'
mysql> SELECT DATE_FORMAT('1997-10-04 22:23:00',
    ->                 '%H %k %I %r %T %S %w');
        -> '22 22 10 10:23:00 PM 22:23:00 00 6'
mysql> SELECT DATE_FORMAT('1999-01-01', '%X %V');
        -> '1998 52'
mysql> SELECT DATE_FORMAT('2006-06-00', '%d');
        -> '00'

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_str-to-date


SELECT DATE_FORMAT(dCreatedDate,'%Y-%m-%d') as date1 FROM tbl_book_self

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号