I want to change the date format in my SQL calling, but I got the wrong output how to solve this?
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
This is how my DB store the format date 2020-10-21 09:25:10
I want to achieve the result of 21/10/2020 09:25:10
How do I fix my current query in order to achieve the result?
My Answer:
You can use the DATE_FORMAT function in MySQL to change the date format in your SQL SELECT query. Here is an updated version of your query:
sql
SELECT s.id, DATE_FORMAT(s.TransacDate,'%d/%m/%Y %H:%i:%s') AS formatDate, s.name
FROM sales s
JOIN user u
ON s.No = u.No
WHERE u.logId= 'abcde';
This query will format the `TransacDate` column in the `sales` table to the desired format of `dd/mm/yyyy HH:MM:SS`.
Rate this post
4 of 5 based on 5684 votesComments