From a string to a date

Hello,
I have a problem oder understanding problem with converation a string in a DateTime value.
In my string, is for the date this text 14.06.2018. Now I would like to check if this value is in the past.

For this to do, I would convert the string to a date value.
But I have no woriking Idea for that :frowning:
Have anyone a hint for me?

Thanks

Peter

Hi.

For your problem, you will want to use ParseExact to convert the string.
There are many examples on this on the forum.

Basically, it would look like this:

Date.ParseExact("14.06.2018", "dd.MM.yyyy", System.Globalization.CultureInfo.CurrentCulture)

EDIT: had a typo

This will only work if the string is in the format that you specify, “dd.MM.yyyy”. So, you will need to maybe surround this by a Try/Catch for times when the string is not a date.

Once it is in a DateTime type you can check the value by using:
yourdatevariable >= Now
et cetera…

Regards.

3 Likes

Hello,
thanks for your help, now works :smile:

Peter