当前位置:网站首页>MySQL timestamp format conversion date format string

MySQL timestamp format conversion date format string

2022-06-24 16:07:00 Full stack programmer webmaster

Hello everyone , I meet you again , I'm your friend, Quan Jun .

1. Test table structure

CREATE TABLE `timestamp_string_change` (
  `id` int NOT NULL AUTO_INCREMENT,
  `up_time` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

2. mysql Timestamp format to string

Method 1 :

select STR_TO_DATE(tsc.up_time, '%Y-%m-%d %H:%i:%s' ) as up_time from timestamp_string_change tsc 

Method 2:

select from_unixtime(unix_timestamp(up_time), '%Y-%m-%d %H:%i:%s' ) as up_time from timestamp_string_change 

notes : Method 2 when , We need to use it first. unix_timestamp() Method to convert data to timestamp format , Reuse from_unixtime() Method to convert a timestamp to a custom format time string . Direct use from_unixtime() Method NULL.

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/151936.html Link to the original text :https://javaforall.cn

原网站

版权声明
本文为[Full stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241545217531.html