Date time issue

Hi,

I have two values 11-05-2019 06:27:00 and 13/05/2019 03:35:00 . I need to convert them to date time format (dd-mm-yyyy) and find out the difference in days. Can anyone please help.

1 Like

Hi @shreyaank

Try the following method.

dateTime1 = DateTime.ParseExact(“11-05-2019 06:27:00”, “dd-MM-yyyy hh:mm:ss”, System.Globalization.CultureInfo.CurrentCulture)
dateTime2 = DateTime.ParseExact(“13/05/2019 03:35:00”, “dd/MM/yyyy hh:mm:ss”, System.Globalization.CultureInfo.CurrentCulture)
dayDifference = (dateTime2 - dateTime1).TotalDays

Hi
This expression would help you resolve this
For this date “11-05-2019”
Str_date1 = DateTime.ParseExact(“11-05-2019 06:27:00”, “MM-dd-yyyy hh:mm:ss”, System.Globalization.CultureInfo.CurrentCulture).ToString(“dd-MM-yyyy”)

And similarly for this

Str_date2 = DateTime.ParseExact(“13/05/2019 03:35:00, "dd/MM/yyyy hh:mm:ss”, System.Globalization.CultureInfo.CurrentCulture).ToString(“dd-MM-yyyy”)

Cheers @shreyaank

how do I get the difference after this? both your dates str_date1 and str_date2 are in string formats right?

1 Like

Hi,

I tried your method , the input which I gave was 11-05-2019 06:27:00 and 11/05/2019 03:32 and the difference im getting is -177.8790856 — not sure why? I difference between the number of days should be zero here

1 Like

Hi @shreyaank

Are you sure used TotalDays?
Result -177.8790856 looks like TotalMinutes.
Or maybe you need to change format of date as follow.
dateTime2 = DateTime.ParseExact(“11/05/2019 03:32”, “dd/MM/yyyy hh:mm”, System.Globalization.CultureInfo.CurrentCulture)

here you go with a xaml
hope its resolve
timedifference.zip (9.5 KB)

Cheers @shreyaank