Check if Date is still valid today

Hello, I hava a string with date “14.02.2023” I hould like to know if this date is before or after current date.

Hello @tomaz
Use If condition

DateTime.ParseExact("14.02.2023","dd.MM.yyyy",system.Globalization.CultureInfo.InvariantCulture)>datetime.now.Date

If the given date is after than Today it goes to then sequence, otherwise goes to else

Hi @tomaz

You can use something like

If DateTime.ParseExact("14.02.2023", "dd.MM.yyyy", CultureInfo.InvariantCulture).CompareTo(DateTime.Now) < 0 Then 'inputDate is before the current date ElseIf DateTime.ParseExact("14.02.2023", "dd.MM.yyyy", CultureInfo.InvariantCulture).CompareTo(DateTime.Now) > 0 Then 'inputDate is after the current date

Hi @tomaz ,

You can convert the given string to date format and compare with today’s date, the ouput of the CompareTo function will be -1,0 or 1
1 → Given date is greater than current date
0 → Given date is equal to current date
-1 → Given date is older than current date

Date.ParseExact(DateString,“dd.MM.yyyy”,System.Globalization.CultureInfo.InvariantCulture).CompareTo(now.date)