Assume that I have two columns, first column having time values like 1:52PM. I have to add 18hrs and I got the second column values.if the second column values not matched with the 18hrs time value . I will pass the empty values or else I will write the time values in the excel.
Thanks in advance
Hi @Iswarya_P1
You can transform the data like this & do the comparison in the For Each loop:
timeValue = row("Time").ToString()
parsedTime = DateTime.ParseExact(timeValue, "h:mmtt", CultureInfo.InvariantCulture)
parsedTime is a variable of data type DateTime
updatedTime = parsedTime.AddHours(18)
updatedTime is again a variable of data type DateTime
In the If condition,
If updatedTime = DateTime.ParseExact(row(“secondColumnName”).ToString, "h:mmtt", CultureInfo.InvariantCulture)
Then the time are matching & you can proceed with the actions based on the output.
Hope this helps,
Best Regards.
Hi @Iswarya_P1 ,
I’d suggest you do the activities in the excel using formulas itself and then do auto fill range to drag it to the entire column.
add 18 hours to your time and then use an If to check it with second column.
Hope this helps
Parvathy
(PS Parvathy)
June 8, 2023, 2:33pm
4
Hi @Iswarya_P1
Follow the below steps to achieve required output:
Excel Application Scope (provide the path to your Excel file)
Read Range (store the data in a DataTable variable)
For Each Row (in DataTable)
Assign:
- TimeValue = DateTime.ParseExact(row(“FirstColumn”).ToString(), “h:mmtt”, CultureInfo.InvariantCulture)
- ModifiedTimeValue = TimeValue.AddHours(18).ToString(“h:mmtt”)
If:
- Condition: ModifiedTimeValue = “7:52AM” (replace with your desired condition)
- Then:
- Set Row Item: row(“SecondColumn”) = ModifiedTimeValue
- Else:
- Set Row Item: row(“SecondColumn”) = String.Empty
Write Range (write the modified DataTable back to the Excel file)
Hope it helps!!
Regards,
system
(system)
Closed
June 16, 2023, 11:11am
5
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.