可以使用EXTRACT() 函数。(oracle和mysql都有该函数) 语法:
EXTRACT(unit FROM date) date 参数是合法的日期表达式。unit 参数可以是下列的值:YEAR\MONTH\WEEK\DAY\HOUR\MINUTE\SECOND上面依次代表:年、月、周、日、时、分、秒 示例:table 表id为1的数据有一个日期类型的字段 createDate 值为 2019-11-12 10:12:33 select
EXTRACT(YEAR FROM createDate) as createYear,
EXTRACT(MONTH FROM createDate) as createMonth,
EXTRACT(DAY FROM createDate) as createDay from table where id = 1 结果:
createYear -- 2019
createMonth -- 11
createDay -- 12
原文地址:https://www.cnblogs.com/marvinn/p/10441820.html
时间: 2024-11-09 03:57:41