简体   繁体   English

MySQL语法错误-date_format

[英]mysql syntax error - date_format

I am trying to format a datetime field in php, but i get this error code: 我正在尝试在php中格式化日期时间字段,但出现此错误代码:

You have an error in your SQL syntax; check the manual that  
corresponds to your MySQL server version for the right syntax  
to use near 'DATE_FORMAT(date, '%b %d 

This is my whole code: 这是我的整个代码:

SELECT * FROM topics, DATE_FORMAT(date, '%b %d %Y, %h:%i %p') AS f_date  

I've checked everything, this is usually how I do my formatting, compared the code to other formattings ive done. 我已经检查了所有内容,通常这就是格式化的方式,将代码与已完成的其他格式化进行了比较。
Any help with what's wrong? 有什么问题的帮助吗?

尝试SELECT *, DATE_FORMAT(date, '%b %d %Y, %h:%i %p') AS f_date FROM topics

You can't select all (*) and then add columns with that syntax. 您不能选择全部(*),然后使用该语法添加列。 It can be done like this: 可以这样完成:

SELECT topics.*, DATE_FORMAT(date, '%b %d %Y, %h:%i %p') AS f_date FROM topics

Edit: as @Vyacheslav Voronchuk points out, you can use just * instead of topics.* if you only query a single table. 编辑:正如@Vyacheslav Voronchuk指出的那样,如果仅查询单个表,则只能使用*代替topics.*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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