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
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,
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
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)
- TimeValue = DateTime.ParseExact(row(“FirstColumn”).ToString(), “h:mmtt”, CultureInfo.InvariantCulture)
- ModifiedTimeValue = TimeValue.AddHours(18).ToString(“h:mmtt”)
- Condition: ModifiedTimeValue = “7:52AM” (replace with your desired condition)
- Set Row Item: row(“SecondColumn”) = ModifiedTimeValue
- Set Row Item: row(“SecondColumn”) = String.Empty
- Write Range (write the modified DataTable back to the Excel file)
Hope it helps!!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.