Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

347
Views
What does a single quote inside a C# date time format mean?

We have e.g. this constant in C#:

System.Globalization.DateTimeFormatInfo.InvariantInfo.SortableDateTimePattern

It has this value:

"yyyy'-'MM'-'dd'T'HH':'mm':'ss"

I do use it in the ParseExact function and then yyyy-MM-ddTHH:mm:ss works as well.

I cannot figure out what the single quotes are for.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

It's a literal string delimiter.

Anything between the single quotes is interpreted as a literal character, and will not be interpreted as a custom format string.

They are equivalent to escaping using a backslash: dd'T'HH is the same as dd\THH.

In your string yyyy'-'MM'-'dd'T'HH':'mm':'ss, the quotes are unnecessary around the - and T, as those are not custom format strings, and so will always be interpreted as string literals. However : is a format specifier, which evaluates to a time separator that's suitable for the current culture. Quoting it as ':' means that the literal character : will always be used, regardless of the current culture.

over 4 years ago · Santiago Trujillo Report

0

It's useful to know that this is the same format used by the Windows GetDateFormat function. You use apostrophe's to indicate some literal you want inserted into the resulting string.

More documentation of the string formatting codes can be found on:

  • Day, Month, Year, and Era Format Pictures

In your string it is indiating that it literally wants to add hyphens, colons, and the T characters:

yyyy '-' MM '-' dd 'T' HH ':' mm ':' ss

In general you don't want to construct dates/times with literally a hyphens (-) or colons (:), or even slashes (/). Because those are wrong for cultures that don't use slashes and colons to construct dates/times:

  • 10/22/2019 10∶19∶54 ᴀᴍ
        1. 10:19:54
  • 2019.10.22 10:19:54
  • 2019-10-22 10.19.54
  • 2019-10-22 10:19:54
  • 2019-10-22 10:19:54 AM
  • 2019-10-22 ཆུ་ཚོད་10:19:54 སྔ་ཆ་
  • 2019-10-22 오전 10:19:54
      1. 2019 10:19:54
        1. 10:19:54
  • 22.10.19 10:19:54
  • 22.10.19 ý. 10:19:54
  • 22.10.2019 10.19.54
  • 22.10.2019 10:19:54
  • 22.10.2019 10:19:54 p.d.
  • 22.10.2019 г. 10:19:54
  • 22.10.2019. 10:19:54
  • 22-10-19 10.19.54
  • 22-10-19 10.19.54 AM
  • 22-10-19 10:19:54
  • 22-10-19 ਸਵੇਰ 10:19:54
  • 22-10-2019 10:19:54
  • 22-10-2019 ৰাতিপু 10:19:54
  • 22-окт. 19 10:19:54
  • 23/02/41 10:19:54 ص
  • 30/07/1398 10:19:54 ق.ظ

What you would want to do, if you want to indicate:

  • "here is where you should put the date separator"
  • "here is where you should put the time separator"

Is use the special:

  • date separator replacement character (/)
  • time separator replacement character (:)

And construct a format such as:

dd/yyyy/MM ss:HH:mm

I don't know what business need one might have to show a date as:

  • 22/2019/10 37:10:24
  • 22-2019-10 37∶10∶24
  • 22//2019//10 37::10::24
      1. 10 37∶10∶24

But this way the localizer will insert the culture's correct date and time separators.

Whereas if you literally asked for /, -, or ::

  • dd '/' yyyy '/' MM ss ':' HH ':' mm

You will literally get:

  • 22/2019/10 37:10:24

rather than:

  • 22-2019-10 37∶10∶24
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!