Is there any good way to change all of the following string dates to DateTime type?
01/01/2021 00:00:00 ←DD/MM/YYYY 00:00:00
The above three values are all imported in the same String variable.
So I’m looking for a way to get these three different formats to come in and still be properly stored in a DateTime type variable as January 1, 2021.
【What I did】
At first I used “Convert.ToDateTime(DateStringVariable)” to convert, but with the advent of 21/01/01, I ran into a problem where I could not convert.
And next, I was converting “21/01/01” to “2021/01/01” by putting 20 in front of it, but next came “01/01/2021 00:00:00” and I am encountering the problem of not being able to convert with “2001/01/2021 00:00:00”.
Therefore, I thought of a process to convert “21/01/01” to “2021/01/01” based on whether the target string contains “2021” or not as one method, but it turned out that I could not judge by 2021 because I needed to process 2021 in 2022.
To be honest, I have not found a good way to do this.
If you know anything about this, please let me know.
Thank you very much.