[英]How do I change date format in SQL SELECT?
I want to change the date format in my SQL calling, but I got the wrong output how to solve this?我想在我的 SQL 调用中更改日期格式,但我得到了错误的 output 如何解决这个问题?
SELECT s.id, format(s.TransacDate,'dddd, d MMMM, yyyy') AS formatDate, s.name
FROM sales s
JOIN user u
ON s.No = u.No
WHERE u.logId= 'abcde';
OUTPUT DATE THAT I GET FROM THE QUERY OUTPUT 从查询中获得的日期
This is how my DB store the format date 2020-10-21 09:25:10
这就是我的数据库存储格式日期
2020-10-21 09:25:10
的方式
I want to achieve the result of 21/10/2020 09:25:10
我想达到
21/10/2020 09:25:10
的结果
How do I fix my current query in order to achieve the result?如何修复当前查询以达到结果?
Seems that "format" is the MSSQL function.似乎“格式”是MSSQL function。 For MySQL, try date_format :
对于 MySQL,尝试date_format :
date_format(s.TransacDate, '%d/%m/%Y %H:%i:%s')
This will be correct answer.这将是正确答案。
SELECT s.id, format(s.TransacDate.getdate(),'dd/MM/yyyy,hh:mm:ss') AS formatDate, s.name
FROM sales s // --------------------
JOIN user u // ^--------------------- change here
ON s.No = u.No
WHERE u.logId= 'abcde';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.