D
D
Dealaxer2019-03-16 15:35:29
.NET
Dealaxer, 2019-03-16 15:35:29

How to recognize date format and compare it in VB.NET?

There is a file today and it contains a line with a date in the format 20190314, tomorrow the format in the file can change to 15032019 and all without separators.
How can these formats be recognized, converted, compared and manipulated.
Well, for example, if we have a string value of 20190314, then we need to convert it somehow into a date and understand what kind of format it is and convert it to 14032019, and if the format is 15032019, then to 20190315.
If the date had separators, then everything is solved simply, but the date has no separators.
Tell me where to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2019-03-16
@2ord

The date format recorded in the file depends on what regional settings are set on the computer from which the file came. In .NET it is possible to parse the date depending on the CultureInfo. However, in the case of logs, XML/JSON or DBMS, ISO 8601 or ODBC canonical date may apply.
Help:
DateTime. TryParseExactDateTime
. TryParse
https://docs.microsoft.com/en-us/dotnet/api/system...
https://tableplus.io/blog/2018/09/sql-server-date-...
https:// www.itprotoday.com/sql-server/solving-date...
Once a date is stored in a DateTime variable, it can be compared with variables of the same type.
If the date format is unknown, then it remains only to select heuristically.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question