0

In our api we need to receive parameters for dates and also for time-spans, but we need to be consistent with the format.

What is the ISO standard to represent in the same form a date and also a time-span?

I've seen ISO 8601 Date and Time Formats but I don't see how to represent a date using this format...

Buda Gavril
  • 21,409
  • 40
  • 127
  • 196
  • 1
    What *exactly* do you mean by a time-span here? ISO-8601 dates are just yyyy-MM-dd (or yyyyMMdd) but they definitely don't represent timespans. The idea of trying to use the same format for both dates and timespans makes no sense to me... *why* are you trying to use the same format? – Jon Skeet Apr 24 '17 at 06:13
  • @JonSkeet We need to represent like from date X to date Y and also to put just a date, but we want to keep the same format if it is possible – Buda Gavril Apr 24 '17 at 06:15
  • And with this standard we can represent a timespan like "P2M5D" (2 months and 5 days) – Buda Gavril Apr 24 '17 at 06:16
  • Apparently [XmlConvert](http://stackoverflow.com/questions/12466188/how-do-i-convert-an-iso8601-timespan-to-a-c-sharp-timespan) can handle it. – ProgrammingLlama Apr 24 '17 at 06:24
  • I know that, but I've asked about the date format, not how to convert a string to a date or timespan – Buda Gavril Apr 24 '17 at 06:28
  • 2
    But "date X to date Y" and "date X" are *not the same thing* - why would you want to represent them in the same way? And yes, ISO-8601 does have things like P2M5D, but again that's different from a date or even a date range. It's very, very unclear what your API is trying to represent and what you're really asking about. – Jon Skeet Apr 24 '17 at 06:30
  • Buda How would you represent a datetime in the same way as a timespan? How would you represent 5 months? The representations are not the same because the data is not the same. – ProgrammingLlama Apr 24 '17 at 07:43

0 Answers0