Assign difference in a row's datetime to column


I am trying to calculate the difference between data in two columns of the datetime type for a row, and then assign it to a third column. I have tried reading up here on the forum, but I can’t seem to get it to work. What am I doing wrong?



1 Like

Refer this to get clear view of subtraction of date time.:slight_smile:

1 Like

Hi @Jakob_Petersen

give on the RHS as row.item(“EndTime”)-row.item(“StartTime”)

try to do Cdate function and check it

Ashwin S

I don’t understand “give on the RHS” and “try to do Cdate function”… :frowning:

Hi @Jakob_Petersen
before that do Cdate(row.item(“EndTime”).ToString(“hh:mm:ss”)-CDate( row.item(“StartTime”).ToString(“hh:mm:ss”)

try this

Ashwin S

hope this expression would help you on this
row(“Hours”) = (Datetime.ParseExact(row(“EndTime”).ToString.SubString(0,10),“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture).Hour - Datetime.ParseExact(row(“StartTime”).ToString.SubString(0,10),“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture).Hours).ToString

Cheers @Jakob_Petersen

Thank you all for your input, but I made it work in the following way for anyone else that is interested:


With the first and second assign looking like this:

d1 = Datetime.ParseExact(row.Item(“StartTime”).ToString,“MM/dd/yyyy HH:mm:ss”,System.Globalization.CultureInfo.InvariantCulture)

d2 = Datetime.ParseExact(row.Item(“EndTime”).ToString,“MM/dd/yyyy HH:mm:ss”,System.Globalization.CultureInfo.InvariantCulture)

and the third assign looking like this:

timeDiff = (d2.Subtract(d1)).ToString(“hh:mm:ss”)