Jumbo
(Jumbo Suzuki)
March 7, 2018, 4:47am
1
Hi all,
Does anybody know how to simple way how to extract data table items from the table that was read from Excel file?
In my case, there is 3 column in a Excel, ID, Name and DateTime, for example. And when I read it with Read-range activity, all data will be read as String format and I cannot use Datatable.select activity with date time fo-rmat. (Like Datetime < now() - 1 day.)
Indeed, it is able to separate data if I use for each row and convert string to Datetime format but I think it might be poor performance…
So, if anybody know good way to select data table with date time format, please kindly let me know.
Regards,
J,
1 Like
arivu96
(Arivazhagan A)
March 7, 2018, 4:52am
2
Hi @Jumbo ,
Use this way to convert string to date time.
DateTime.ParseExact(str_PrevDate, "MM/dd/yyyy", CultureInfo.InvariantCulture)
Regards,
Arivu
Jumbo
(Jumbo Suzuki)
March 7, 2018, 4:59am
3
HI @arivu96 ,
Thanks for your reply but it’s converting string to date time.
I hope to read Excel column as Date time format instead of String if possible.
Rgds,
J,
arivu96
(Arivazhagan A)
March 7, 2018, 5:15am
4
If it’s in date time format you can directly apply in the condition.
Dt.Select("DateFieldColumn=DateTime.Now")
Regards,
Arivu
Jumbo
(Jumbo Suzuki)
March 7, 2018, 5:29am
5
Hi @arivu96 ,
You right but when I read data from Excel with read range, it default string. And I’m looking for the way to read as DateTime.
Rgds,
J,
MAHESH1
(MAHESHKUMAR JV)
March 7, 2018, 6:33am
6
@Jumbo
Try this
dt.Select(“DateTime='”+DateTime.Now.ToString(“yyyy/M/d H:mm”)+“'”)
There mention the format of date which is present in excel for filtering.
Regards,
Mahesh
arivu96
(Arivazhagan A)
March 7, 2018, 7:04am
7
Hi @Jumbo ,
Try this code
dt.Select("Convert(DateTime,System.DateTime)>DateTime.Now.AddDays(-1)")
Regards,
Arivu
Jumbo
(Jumbo Suzuki)
March 7, 2018, 7:43am
8
Hi @arivu96 , @MAHESH1 ,
I tried both of your solution but it does not work… I attached my sample data file so if possible could you provide me sample code for this?
Book1 .xlsx (9.6 KB)
Syntax error will be occurred when assign it…
Regards,
J,
MAHESH1
(MAHESHKUMAR JV)
March 7, 2018, 7:45am
9
@Jumbo
whart error you are getting
and in you data, which rows you have to extract
do you want to extract only today’s date
Regards,
Mahesh
MAHESH1
(MAHESHKUMAR JV)
March 7, 2018, 7:55am
10
@Jumbo
Try this
@Jumbo
Try this
dt.Select(“DateTime=’”+DateTime.Now.ToString(“yyyy/M/d H:mm”)+“’”)
There mention the format of date which is present in excel for filtering.
Regards,
Mahesh
Jumbo
(Jumbo Suzuki)
March 7, 2018, 8:20am
11
Hi @MAHESH1 ,
I tried below code but does not work with error.
Error
My Date time format in data table.
What is problem of this??
Best regards,
J,
MAHESH1
(MAHESHKUMAR JV)
March 7, 2018, 8:34am
12
@Jumbo
Try this
(From p in dtbsheet1.Select()
where Date.Now.ToString(“MM/dd/yyyy HH:mm:ss”).Equals(Convert.Tostring(p.Item(“DateTime”))
Select p).ToArray.CopyToDataTable
Regards,
Mahesh
Jumbo
(Jumbo Suzuki)
March 8, 2018, 1:37am
13
Hi @MAHESH1 ,
Thanks for your reply but it does not work with compile error…
I think it is lack of “)” and something other part of formula, because “.ToArray” is List class method.
Could you check it again?
Rgds,
J,
arivu96
(Arivazhagan A)
March 8, 2018, 2:45am
14
HI @Jumbo ,
Try this code
(From p In dtbsheet1.Select() Where Convert.ToDateTime((p.Item("DateTime")))<Date.Now Select p).ToArray.CopyToDataTable
Regards,
Arivu
1 Like
Jumbo
(Jumbo Suzuki)
March 8, 2018, 3:03am
15
Hi @arivu96 ,
Great!! it works. Thanks for your many help
This code: Convert.ToDateTime((p.Item(“DateTime”))) is what I intended to!!
Best regards,
J,
arivu96
(Arivazhagan A)
March 8, 2018, 3:05am
16
Converting to date time value
MAHESH1
(MAHESHKUMAR JV)
March 8, 2018, 6:09am
17
@Jumbo
Sry I missed, replace Date.Now with DateTime.Now
Regards,
Mahesh
Jumbo
(Jumbo Suzuki)
March 8, 2018, 6:31am
18
Hi @MAHESH1 ,
I have already tried that but does not work, I think one or more typo exist but I couldn’t found it…
Rgds,
J,
MAHESH1
(MAHESHKUMAR JV)
March 8, 2018, 6:46am
19
@Jumbo
I tried its working for me
(From p In dta.Select()
Where DateTime.Now.ToString(“MM/dd/yyyy HH:mm:ss”).Equals(Convert.Tostring(p.Item(“DateTime”)))
Select p).ToArray.CopyToDataTable
Regards,
Mahesh
2 Likes
Jumbo
(Jumbo Suzuki)
March 8, 2018, 6:51am
20
Hi @MAHESH1 ,
Thanks for your code and now it’s work. (might be lack of “)” in previous post.)
Rgds,
J,