Keesver 23 Posted January 21, 2022 According to this document ISO 8601 - Wikipedia Monday 29 December 2008 is written as "2009-W01-1" when a week number is used. As you can see, instead of 2008, the value 2009 is shown. What date formatting function supports this in Delphi? Thanks Share this post Link to post
Roger Cigol 103 Posted January 21, 2022 I can't help here. But I can offer a warning to inexperienced "week number" users (which you may NOT be, I realise) and that is to beware of the week number 53 that does occur from time to time. I spent a long time debugging someone elses code once that stored week data in an array size [52] and overflowed causing corruption when week 53 came along. Share this post Link to post
timfrost 78 Posted January 21, 2022 The functions in system.dateutils claim to be ISO8601 compliant. Are you saying that they return the wrong results? WeekOfTheYear has an overload which sets the year as well as returning the week Share this post Link to post
Keesver 23 Posted January 21, 2022 (edited) WeekOfTheYear is working. I was looking for something like DateTimeToString which supports displaying dates like above using week numbers (aka "2009-W01") Edited January 21, 2022 by Keesver Share this post Link to post
Attila Kovacs 629 Posted January 21, 2022 (edited) 28 minutes ago, Keesver said: I was looking for something like DateTimeToString There is no such thing in Delphi. You have to roll your own. Should not be that hard. Edited January 21, 2022 by Attila Kovacs Share this post Link to post
dummzeuch 1505 Posted January 22, 2022 I was about to point to my iso8601 unit in dzlib, but when I checked, I found the ToWeekDate method to be possibly faulty in exactly these cases. Should be easy to fix though. https://osdn.net/projects/dzlib-tools/svn/view/dzlib/trunk/src/u_dzIso8601.pas?view=markup&root=dzlib-tools It's ISO 8601 btw. not 8901. Share this post Link to post
dummzeuch 1505 Posted January 22, 2022 7 hours ago, dummzeuch said: I was about to point to my iso8601 unit in dzlib, but when I checked, I found the ToWeekDate method to be possibly faulty in exactly these cases. Should be easy to fix though. https://osdn.net/projects/dzlib-tools/svn/view/dzlib/trunk/src/u_dzIso8601.pas?view=markup&root=dzlib-tools Fixed it. Also added unit tests for this (I could have sworn I already had some. Another faulty thing: My memory.) 2 2 Share this post Link to post