It sounds like you’re trying to scrape an excel sheet for the dates, is that correct?
It sounds like you’re doing it correctly, likely doing a read range, grabbing all of the data out and exporting it to a datatable, and then for each row to check it. When you get data out of an excel sheet, the problem is that it doesn’t know that a date is a date, it thinks it’s just a normal string. You will have to parse the string in order to convert to a datetime object or simply to get out the month if that’s all you need.
As a way to figure it out, I would suggest creating a new sequence and assign one of the string dates to a variable and try parsing just the one without dealing with the excel sheet. That way you can ensure that you’re able to process dates how you’d expect and you can then use what you learned in your automation.
Edit: I would suggest trying to figure it out on your own and reading up on VB’s DateTime object, but, if you just want the answer, here’s a sample of a way to do it: Test_StringToDate.xaml (4.8 KB)
you can get the date time type for this
Try like this to convert tgis Value to a datetime
Once reading with for each row loop assign the the value of the column month to
@eelin
When you scrape data, the date format will be returned as string. Use Log and check in which format date column is saved in datatable.
Instead of using foreach loop and declaring multiple variables, use filter data table activity by specifying the required column and the date in the format that you are receiving in datatable.
hope this helps!
Before going for if condition using an assign activity create a variable named Date_Condition with datatime datatype to store the value of condition 1/1/2019
Like
Date_Condition = Convert.Datetime(“1/1/2019”,“d/M/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
Write if condition like this buddy
Datetime.ParseExact(row(“Month”),“d/M/yyyy”,System.Globalization.CultureInfo.InvariantCulture) = Date_Condition and AccName= “TRAVEL-TRIP”
However, i would like to assign the Month= row.Item(0).ToString
I need to get the data for the month.
How can i actually assign the variable “Month” to get the date and then make it can read it as date format, then with some condition, i need to use write line activity to get some output.
Besides, i need to get the data from different month.
The condition will be as below:-
row item that fulfill (AccName= “TRAVEL-TRIP” and Month= " 1/1/2019")
to get the data for the month using for each row loop to iterate throught the row and use a assign activity like below buddy Month = Datetime.ParseExact(row.item(0).ToString,“d/M/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
Where Month is of type Datetime
Inorder to mention that in writeline activity write like Month.Tostring
write condition like AccName = “TRAVEL-TRIP” and Month = Conver.Datetime(“1/1/2019”)