Monday, March 8, 2021

[MySQL][Resolved] mysql date to string

 We can use DATE_FORMAT() function to convert data from date format to string, 

the first parameter is the source data and the second paramter is the pattern.

for the pattern you can look up table in this page:

https://www.w3schools.com/sql/func_mysql_date_format.asp


Example:

SELECT CATE_CODE, 

    (CASE WHEN INACTIVE_DATE IS NOT NULL THEN "Y" ELSE "N" END AS IS_INACTIVE) AS IS_INACTIVE, 

    CRE_USER,

    DATE_FORMAT(CRE_DATE,'%d/%m/%Y %H:%i') AS CRE_DATE,

    AMD_USER,

    DATE_FORMAT(AMD_DATE,'%d/%m/%Y %H:%i') AS AMD_DATE

FROM

    TABLE_CATE;


No comments :

Post a Comment