Function dateFormat()
calculates a time value into a string in the specified format and returns that string.
Arguments:
- Time <datetime | timestamp | string>
- Format <string>
Returns:
- Time string <string>
Code of format:
Code |
Description | Example |
---|---|---|
%a | Abbreviated name of day of week in system language | (en_US) Sun, Mon, ... |
%A | Full name of day of week in system language | (en_US) Sunday, Monday, ... |
%b | Abbreviated name of month in system language | (en_US) Jan, Feb, ... |
%B | Full name of month in system language | (en_US) January, February, ... |
%c | Default date and time format in the system settings | 'Wed Jan 11 10:59:28 2023' |
%C | Number denoting century (year divided by 100) | 00, 01, ..., 99 |
%d | Day of month (zero-padded) | 01, 02, ..., 31 |
%D | Alternative code of %m/%d/%y |
'01/11/23' |
%e | Day of month | 1, 2, ..., 31 |
%Ez | Time zone | '+08:00' |
%g | Year in 2 digits (without century) | 00, 01, ..., 99 |
%G | Year in 4 digits | 0000, 0001, ..., 9999 |
%h | Alternative code of %b |
See example of %b |
%H | Hour of 24-hour clock (zero-padded) | 00, 01, ..., 23 |
%I | Hour of 12-hour clock (zero-padded) | 01, 02, ..., 12 |
%j | Day of year (zero-padded) | 001, 002, ..., 366 |
%m | Code of month (zero-padded) | 01, 02, ..., 12 |
%M | Minute (zero-padded) | 00, 01, ..., 59 |
%n | Line break | |
%p | AM or PM | (en_US) AM, PM |
%P | am or pm | (en_US) am, pm |
%r | Alternative code of %I/%M/%S %p |
'01:49:23 AM' |
%R | Alternative code of %H:%M |
'13:49' |
%S | Second (zero-padded) | 00, 01, ..., 59 |
%t | Tab | |
%T | Alternative code of %H:%M:%S |
'23:02:05' |
%u | Code of day of week, where 1 stands for Monday ( or 1 for Sunday in a Sun Solaris system | |
%U | Week of year (zero-padded) with the first Sunday being the first day of the week 01 | 00, 01, ..., 53 |
%V | Week of year (zero-padded) with the first day till the first Sunday being week 01 if they have no less than 4 days, or being the last week of the previous year if less than 4 days | 01, 02, ..., 53 |
%W | Week of year (zero-padded) with the first Monday being the first day of the week 01 | 00, 01, ..., 53 |
%w | Code of day of week, where 0 stands for Sunday | 0, 1, ..., 6 |
%x | Default date format in the system settings | '01/11/23' |
%X | Default time format in the system settings | '06:38:45' |
%y | Alternative code of %g |
See example of %g |
%Y | Alternative code of %G |
See example of %G |
%z | UTC offset in the form ±HHMM[SS] | +0000, -0400, +1030, ... |
%Z | Time zone name | GMT, UTC, IST, CST, ... |
%% | Character % | % |
Common Usage
Example: Direct calculate
uncollect ["2023-04-30 22:30:35", "2020-01-15 09:03:16"] as a
uncollect ["%y-%m-%d %R", "%Y/%m/%d %r"] as b
return table(a, b, dateFormat(a, b))
| a | b | dateFormat(a, b) |
|---------------------|-------------|------------------------|
| 2023-04-30 22:30:35 | %y-%m-%d %R | 23-04-30 22:30 |
| 2020-01-15 09:03:16 | %Y/%m/%d %r | 2020/01/15 09:03:16 AM |
Example: Multiply and calculate
uncollect ["2023-04-30 22:30:35", "2020-01-15 09:03:16"] as a
uncollect ["%y-%m-%d %R", "%Y/%m/%d %r"] as b
with dateFormat(a, b) as c
return table(a, b, c)
| a | b | c |
|---------------------|-------------|------------------------|
| 2023-04-30 22:30:35 | %y-%m-%d %R | 23-04-30 22:30 |
| 2023-04-30 22:30:35 | %Y/%m/%d %r | 2023/04/30 10:30:35 PM |
| 2020-01-15 09:03:16 | %y-%m-%d %R | 20-01-15 09:03 |
| 2020-01-15 09:03:16 | %Y/%m/%d %r | 2020/01/15 09:03:16 AM |