Hi,
I need to get the last hour from “Action_time ” column of an excel file of today’s date.
format should be fixed.
You have to change time and date when you contruct code.
for ur refrence i am giving the file.
New Microsoft Excel Worksheet (2).xlsx (12.4 KB)
here in this file u see the output sheet from that u will understand what I am trying to say.
let’s take some example: suppose today’s date is 24-11-2022 and the time is 7.05 pm
here I am downloading the file from browser in which I which date time column where I have to filter last hour data i.e. (6 pm to 7pm) date will be today’s date.
1 Like
Yoichi
(Yoichi)
November 24, 2022, 2:19pm
2
Hi,
How about the following sample?
dt = dt.AsEnumerable.Where(Function(r) DateTime.Parse(r("Action_time").ToString)>=currentDateTime.Date.AddHours(currentDateTime.Hour-1) AndAlso DateTime.Parse(r("Action_time").ToString)<currentDateTime.Date.AddHours(currentDateTime.Hour)).CopyToDataTable()
Sample20221124-4aL.zip (12.5 KB)
Regards,
1 Like
can u please tell me why u use this “New DateTime(2022,11,24,19,5,0)”
1 Like
Yoichi
(Yoichi)
November 25, 2022, 5:53am
4
Hi,
This is for your assumption.
suppose today’s date is 24-11-2022 and the time is 7.05 pm
In actual use, it should be Now
instead of New DateTime(2022,11,24,19,5,0)
Regards,
I am doing this “CDate(Now.ToString(“dd-MM-yyyy”)) ”
what I am doing wrong
please tell me
Yoichi
(Yoichi)
November 25, 2022, 9:34am
7
Hi,
Can you try to modify as the following?
CurrentDateTime = Now
Then use same expression.
dt = dt.AsEnumerable.Where(Function(r) DateTime.Parse(r("Action_time").ToString)>=currentDateTime.Date.AddHours(currentDateTime.Hour-1) AndAlso DateTime.Parse(r("Action_time").ToString)<currentDateTime.Date.AddHours(currentDateTime.Hour)).CopyToDataTable()
Regards,
1 Like
when I am doing CurrentDateTime = Now it shown an error in your code as well as in my code.
Yoichi
(Yoichi)
November 25, 2022, 10:02am
9
HI,
Can you share screenshot of the error?
Regards,
Assign: The source contains no DataRows.
1 Like
Yoichi
(Yoichi)
November 25, 2022, 10:12am
11
Hi,
This mean there is no row as filter result.
The above expression assumes there is one or more rows as result.
Can you try as the following?
Please replace .CopyToDataTable with .ToArray
arrDr = dt.AsEnumerable.Where(Function(r) DateTime.Parse(r("Action_time").ToString)>=currentDateTime.Date.AddHours(currentDateTime.Hour-1) AndAlso DateTime.Parse(r("Action_time").ToString)<currentDateTime.Date.AddHours(currentDateTime.Hour)).ToArray()
Then check arrDr.Any() using If activity
note: arrDR is dataRow array type.
Regards,
Nothing Happen
here is the Xaml file.
Sample20221124-4aL.zip (19.1 KB)
Yoichi
(Yoichi)
November 25, 2022, 2:42pm
13
Hi,
In my environment, it works well as the following.
(I modified now to currentDateTime = New DateTime(2022,11,25,16,30,0) because current local time is 23:40 in my place.
Can you try again and check your input file if there is rows which should be extracted?
Regards,
1 Like
I did not get the solution yet of that problem so please help me
1 Like
Yoichi
(Yoichi)
November 29, 2022, 6:19am
15
HI,
Can you share your latest sample data?
Regards,
Anil_G
(Anil Gorthi)
November 29, 2022, 7:36am
17
Hi @Lakshya_Garg2
May I know that is your output time changing from 13 to 14?
cheers
Yoichi
(Yoichi)
November 29, 2022, 8:24am
18
Hi,
I’d like confirm the following is same as what you expect.
As input data is 2022/10/25, target date is set as 2022/10/25 15:10:00 as the following.
Then the following is result data. Is this what you expect?
If you need to filter it as actual current time, please modify it like Now instead of New DateTime(2022,10,25,15,10,0)
Sample20221124-4aL.zip (22.2 KB)
Regards,
yes u can change time according to ur system time