云日志服务 LTS-日期和时间函数:date_format函数

时间:2024-07-25 10:14:31

date_format函数

将时间戳类型的日期和时间表达式转换为指定格式的日期和时间表达式。与time_format函数功能一致。

语法:date_format(expr, format)

表45 参数说明

参数名称

描述

类型

是否必选

expr

日期和时间表达式,格式为yyyy-MM-dd HH:mm:ss.SSS

String

format

时间格式

String

返回值类型:String类型

示例:SELECT DATE_FORMAT(current_timestamp(),'%H%i')

表46 查询分析结果

类型

场景

查询语句

DATE_FORMAT(current_timestamp(),'%H%i')

返回结果

1432

format描述:

%a Abbreviation for the week. For example, Sun and Sat.

%b Abbreviation of the month. For example, Jan and Dec.

%c Month. Numeral type. Range: 1-12.

%D Day of the month. The value must be suffixed, for example, 0th, 1st, 2nd, and 3rd.

%d Day of the month. The value ranges from 01 to 31 in decimal notation.

%e Day of the month. The value ranges from 1 to 31 in decimal notation.

%H Hour, 24-hour system.

%h Hour, 12-hour system.

%i Minute. Numeral type. Range: 00–59.

%j Day of the year. The value ranges from 001 to 366.

%k Hour. The value ranges from 0 to 23.

%l Hour. The value ranges from 1 to 12.

%M The English expression of the month, for example, January, December.

%m Month. Numeral format. The value ranges from 01 to 12.

%p AM and PM.

%r Time in the 12-hour format. The format is hh:mm:ss AM/PM.

%S Indicates the second. The value ranges from 00 to 59.

%s Indicates the second. The value ranges from 00 to 59.

%T Time, in the 24-hour format of hh:mm:ss.

%v The first week of the year, Monday is the first day of the week. The value ranges from 01 to 53.

%W The name of the day of the week. For example, Sunday and Saturday.

%w Day of the week. Sunday is day 0.

%Y A 4-digit year, for example, 2020.

%y A 2-digit year, for example, 20.

%% Escape character for%.

support.huaweicloud.com/usermanual-lts/lts_07_0206.html