Hi Team - I need to calculate difference between two string variables saving Date & Time values.
str1 = 09/29/2023 15:12:52
str2 = 09/29/2023 15:23:41
(str2-str1) =?
I need to find the difference between these string variables and output should be in seconds str format.
One more scenario is some times the dates diff may span multiple days too. For above case
str3: 09/30/2023 15:23:41
(str3-str1) = ?
Parvathy
(PS Parvathy)
October 3, 2023, 4:04am
2
Hi @KrishnaKishore
str1 = "09/29/2023 15:12:52"
str2 = "09/29/2023 15:23:41"
str3 = "09/30/2023 15:23:41"
datetime1= DateTime.ParseExact(str1, "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture)
datetime2 = DateTime.ParseExact(str2, "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture)
datetime3 = DateTime.ParseExact(str3, "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture)
timeDifference1= (datetime2 - datetime1).TotalSeconds
timeDifference2= (datetime3 - datetime1).TotalSeconds
Note: str1 , str2, str3 are of DataType System.String. datetime1, datetime2, datetime3 are of DataType System.DateTime. timeDifference1, timeDifference2 is of DataType System.Double
Hope it helps!!
supriya117
(Supriya Allada)
October 3, 2023, 4:09am
3
Hi @KrishnaKishore
First convert the string to datetime variables
dateTime1 = DateTime.ParseExact(str1, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture)
dateTime2 = DateTime.ParseExact(str2, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture)
dateTime3 = DateTime.ParseExact(str3, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture)
Then find the difference(Output is double type)
timeDifference1 = (dateTime2 - dateTime1).TotalSeconds
timeDifference2 = (dateTime3 - dateTime1).TotalSeconds
Gokul001
(Gokul Balaji)
October 3, 2023, 4:42am
4
Hi @KrishnaKishore
Can you try with this expression in the assign activity
date1 = DateTime.ParseExact(str1, "MM/dd/yyyy HH:mm:ss", system.Globalization.CultureInfo.InvariantCulture)
date2 = DateTime.ParseExact(str2, "MM/dd/yyyy HH:mm:ss", system.Globalization.CultureInfo.InvariantCulture)
Calculate the time difference between date1 and date2
timeDifference = date2 - date1
Regards
Gokul
Hi, you can create workflow as follows
(datetime2.Subtract(datetime1)).ToString(“hh:mm:ss”)
Srini84
(Srinivas Kadamati)
October 3, 2023, 5:48am
6
Hi @KrishnaKishore
Check below video for your reference
Hope this may help you
Thanks,
Srini
Thanks @Parvathy , It worked.