how to change timestamp format in mysql

前端 未结 5 1721
不知归路
不知归路 2021-01-26 02:37

Is it possible to change the current 24 hr format like 22:16:08 to something like 10:16:08 in mysql? I want to change how these values are saved. Is it possible or I will just l

5条回答
  •  广开言路
    2021-01-26 03:04

    You should always store date/time values in their native format, which in MySQL is the 24hr format. You can change how they're retrieved with

    SELECT DATE_FORMAT(somedatetimefield, 'format string here')
    FROM table
    

    where the format string options are defined here

    If doing that manually for every query is a problem, you can always create a view to do it for you automatically.

提交回复
热议问题