Sign in Join
Wiki copytemporary

ISO 8601: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11ISO 8601 is a standard issued by the International Organization for Standardization (ISO) for the date and time. According to ISO 8601, the date is as follows:
22
3-` YYYY-MM-DD`
3+```text
4+ YYYY-MM-DD
5+```
46
57where YYYY is a year in the Gregorian calendar , MM is a month between 01 (January) and 12 (December), and DD is the day of the month between 01 and 31.
68
79The time is recorded:
810
9-` HH:MM:SS`
11+```text
12+ HH:MM:SS
13+```
1014
1115where HH has hours after midnight between 00 and 23. The MM is minutes from the beginning of the previous hour between 00 and 59. The SS is seconds from the beginning of the previous minute between 00 and 59.
1216
1317The combined date and time should be marked with the letter "T":
1418
15-` YYYY-MM-DDTHH:MM:SS`
19+```text
20+ YYYY-MM-DDTHH:MM:SS
21+```
1622
1723But often the intermediate letter "T" can be replaced by a space.
1824
1925The time zone can be indicated by marking the time difference between the coordinated universal time (UTC) as follows:
2026
21-` YYYY-MM-DDTHH:MM:SS±HH:MM`
27+```text
28+ YYYY-MM-DDTHH:MM:SS±HH:MM
29+```
2230
2331## Useful functions
2432
2533| Function | Description | Unit |
2634|----|----|----|
2735| DayOfTheMonth | Gives day of month index for a [[TDateTime]] value | DateUtils |
2836| DayOfTheWeek | Gives day of week index for a TDateTime value | DateUtils |
2937| DayOfTheYear | Gives the day of the year for a TDateTime value | DateUtils |
3038| FormatDateTime | Gives a string representation of a TDateTime value with a given format | SysUtils |
3139| WeekOf | Gives the week of the year for a TDateTime value | DateUtils |
3240
3341## Example
3442
3543``` pascal
3644program iso_8601_project;
3745
3846Uses SysUtils,DateUtils;
3947
4048// Combined date and time in UTC e.g // 2018-09-26T12:18:47Z
4149function ISO8601_Combined_date_and_time_in_UTC(a_DateTime: TDateTime; a_Time_zone:string):string;
4250begin
4351 result := FormatDateTime( 'yyyy-mm-dd"T"hh:mm:ss', a_DateTime )+a_Time_zone;
4452end;
4553
4654// Week: e.g. 2018-W39
4755function ISO8601_week(a_DateTime: TDateTime):string;
4856begin
4957 result := FormatDateTime('yyyy', a_DateTime)+'-W' +
5058 (WeekOf( a_DateTime )).ToString ;
5159end;
5260
5361// Date with week number: e.g. 2018-W39-3
5462function ISO8601_Date_with_week_number(a_DateTime: TDateTime):string;
5563begin
5664 result := FormatDateTime('yyyy', a_DateTime)+'-W' +
5765 (WeekOf(a_DateTime)).ToString + '-' + (DayOfTheWeek(a_DateTime)).ToString ;
5866end;
5967
6068// Ordinal date: e.g. 2018-269
6169function ISO8601_Ordinal_date(a_DateTime: TDateTime):string;
6270begin
6371 result := FormatDateTime('yyyy', a_DateTime)+ '-'
6472 + (DayOfTheYear( a_DateTime )).ToString ;
6573end;
6674
6775var
6876 aDateTime: TDateTime;
6977begin
7078 aDateTime := now;
7179 WriteLn('Date: '+ FormatDateTime( 'yyyy-mm-dd', aDateTime )); // 2018-09-26
7280 WriteLn('Combined date and time in UTC: ');
7381 WriteLn(' ' + ISO8601_Combined_date_and_time_in_UTC(aDateTime,'+00:00')); // 2018-09-26T12:18:47+00:00
7482 WriteLn(' ' + FormatDateTime( 'yyyymmdd"T"hhmmss', aDateTime )+'Z'); // 20180926T121847Z
7583 Writeln(' ' + ISO8601_Combined_date_and_time_in_UTC(aDateTime,'Z')); //2018-09-26T12:18:47Z
7684 WriteLn('Week: '+ ISO8601_week(aDateTime) ); // 2018-W39
7785 WriteLn('Date with week number: '+ ISO8601_Date_with_week_number(aDateTime)); // 2018-W39-3
7886 WriteLn('Ordinal date: '+ ISO8601_Ordinal_date(aDateTime)); // 2018-269
7987 ReadLn;
8088end.
8189```
8290
8391---
8492*From the Free Pascal wiki, page "ISO 8601", as it stood on 2019-07-08 after a change by Djzepi, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history