Formatting rule for time
DateTime specifies the text (formatted) form of the time. A properly created formatting rule allows bidirectional conversion between a text representation and a value of the
DateTime type without loss of information.
Formatting rule contains both constant items (e.g. separators inside time) and also individual time items. The time items can be in any order. Each time item (day, hour, minute, etc.) has an identifier (character: D, H, M, etc.).
The time entry in the formatting rule is indicated by the percent sign
%, thus distinguishing it from constant items (separators). This is followed by an optional number of digits (where the asterisk
* char means the minimum required size with no zeros from the left, e.g., instead of
01.01. it would be
1.1.). The time entry is terminated with the mandatory time entry identifier.
For example:
"%Y.%m.%d %H:%M:%S.%T"
Syntax of one time item:
%[*|1-9]id
Time items:
y - Only the last two digits of the year (e.g.
24) [
2 digits].
T - millisecond (
0-999) [
3 digits].
The number of digits here means the precision after the decimal point, so 1=tenths, 2=hundredths, and 3=thousandths.
See the
PmDateObject.GetMillisecond method.
D - day of year (
1-366) [
3 digits].
It works only for conversion the time (
DateTime) to the text form.
See the
PmDateObject.GetDayOfYear method.
Wi - week of year (
1-53) [
2 digits] according to
ISO 8601.
It works only for conversion the time (
DateTime) to the text form.
See the
PmDateObject.GetWeekOfYear method.
ws - day of the week starting on Sunday (
0-6) [
1 digit].
It works only for conversion the time (
DateTime) to the text form.
See the
PmDateObject.GetWeekday method.
wm - day of the week starting on Monday (
1-7) [
1 digit] according to
ISO 8601.
It works only for conversion the time (
DateTime) to the text form.
Note! Items do not all have to be entered. But then the information is lost in the text form.
When converting back from text to DateTime it must not miss items from the date part (year, month, day). Other missing items are considered to be 0.
Examples for
DateTime 2024.07.01 09:03:01.080:
- %Y.%m.%d %H:%M:%S.%T
will be "2024.07.01 09:03:01.080".
- %Y.%m.%d %HT%M:%S.%T
will be "2024.07.01 09T03:01.080" (this notation conforms to ISO 8601).
-
%Y-%m-%d %H:%M:%S.%T
will be
"2024-07-01 09:03:01.080" (notation in the form for the
MS SQL database).
-
%Y-%m-%d %H:%M:%S
will be
"2024-07-01 09:03:01" (notation in the form for the
MySQL database).
-
TIMESTAMP'%Y-%m-%d %H:%M:%S.%T'
will be
"TIMESTAMP'2024-07-01 09:03:01.080" (notation in the form for the
Oracle database).
-
#%m %d %Y %H:%M:%S#
will be
#07 01 2024 09:03:01# (notation in the form for the
Microsoft Access,
dBase,
PARADOX databases on setting the direct access).
- %Y.%*m.%*d %*H:%*M:%*S.%T
will be "2024.7.1 9:3:1.080".
- %Y%m%d%H%M%S%T
will be "20240701090301080".
- %Y.%m.%d
will be "2024.07.01".
- %Y/%Wi
will be "2024/26".