Storing Dates

  • Thread starter Thread starter Tim Marsden
  • Start date Start date
T

Tim Marsden

Hi,

What is the best way to store a date as text. I want to be able to read the
date from the external source (config file etc) and be able to interpret it
regardless of the local culture setting. The date may be stored using on
culture and read using another.

Thanks
Tim
 
Using the sortable date/time pattern that conforms to ISO 8601 should give
you the best results.

It is the equivalent of yyyy-MM-ddTHH:mm:ss and can be used by specifying
the output as DateTime.ToString("s"). For this format the seprators are not
affected by the culture.

If the value needs to be timezone sensitive then even better results can be
achieved by converting the value to UTC prior to writing it and converting
the UTC value to local when reading it.

When reading the value use DateTime.ParseExact(<value>, "s", Nothing).
 
Tim,

Tim Marsden said:
What is the best way to store a date as text. I want to be able to read
the date from the external source (config file etc) and be able to
interpret it regardless of the local culture setting. The date may be
stored using on culture and read using another.

In addition to the other replies, you can use
'System.Globalization.CultureInfo.InvariantCulture' for formatting and
parsing the date:

\\\
Imports System.Globalization
..
..
..
Dim s As String = Now().ToString(CultureInfo.InvariantCulture)
Dim d As Date = Date.Parse(s, CultureInfo.InvariantCulture)
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top