MySQL、Oracle中字符串和日期之间的相互转换

MySQL、Oracle中字符串和日期之间的相互转换


MySQL

SELECT
	NOW() AS '获取当前时间',
	DATE_FORMAT( NOW(), '%Y-%m-%d %H:%i:%s' ) AS '日期转字符串',
	STR_TO_DATE( '2023-11-09 08:30:00', '%Y-%m-%d %H:%i:%s' ) AS '字符串转日期' 
FROM
	DUAL 

Oracle

SELECT
	SYSDATE AS '获取当前时间',
	TO_CHAR ( SYSDATE, 'yyyy-mm-dd hh24:mi:ss' ) AS '日期转字符串',
	TO_DATE ( '2023-11-09 08:30:00', 'yyyy-mm-dd hh24:mi:ss' ) AS '字符串转日期' 
FROM
	DUAL

你可能感兴趣的:(笔记,数据库)