Sort by date time not working

thanks guys, Dave help me figure it out. it looks like i just over complicated things.
the code below help me sort the most recent date time to the top.

(From row In status_log_dt Order By DateTime.Parse(row.Item(“date time1”).ToString) descending Select row).CopyToDataTable

the code i was using initially was from another thread, and i notice most solutions suggested using datetime.parseexact with “dd/mm/yyyy” format. i’ve tried several other formats as well, none had worked…

it looks like datetime.parse does not require me to specify the format, so it would do just fine for my needs.

do any of you see any potential future problems from using parse instead of parseexact?

in my opinion yes, i am a developer for over 20 years and i have my own rule since creation of the object oriented languages, i never convert datetime to string unless it is on the frontend and i can assure you the regular activity to sort by date is working as expected as i just tested it here, so if you see something wrong, then it must be your data… :wink:

@Jason_Yao Parse is fine as long as it stays in the current format. You can also just use CDate() which is the same thing but easier to read in my opinion. This is using the current culture info (likely invariant culture, which is essentially US culture) to try and parse the string into a datetime. As long as it stays in US format of “MM/d/yyyy” or “m/d/yyyy” then it should be fine

but looking at his print, how do you know which culture he is at? it just doesnt make sense to me to take something that is in datetime format, convert it to string and then parse it back to datetime to then sort it…

i’m curious what i did wrong in the sort data activity…
below is my property setting for the activity. could you tell me what i did wrong?
image
here is the output, as you can see 10/7 dates are sorted to the top.

i’m from usa, so we’re good here :slight_smile:

thats my point it might be that the system is taking the format like 10 is the day and 7 (6) is the month… oh, but you have a 16 there, so dont use the datatable output to prove that, but really inspect the object of output sort dt activity.

i’m still pretty new to uipath, so is datatable output frown upon? and how do you inspect object? do you do that during run time? also, do we have a consensus that sort datatable is not going to work for my situation?

Just based on the way the datetime is structured, since US is one of the only “MM/dd/yyyy” cultures. And for whatever reason, he is not getting datetime and it appears to be coming in as a string. Good point though, that’s a good debug step - @Jason_Yao what is the output (before doing the conversion) if you put the following in a write line activity: status_log_dt.columns(2).DataType.ToString

like this:

2 Likes

system.object

awesome, i learned a new trick! this is going to save me a ton of time. thanks dude! does it also tell me the data type of each column?

yes, but is not showing on my screenshot, need to hit that down arrow to see more about the datatable.

@Jason_Yao this is why it isn’t working. I’m not sure exactly why it’s not recognizing it isn’t a datetime? For some reason uipath is bringing it into the datatable as an object variable instead. So you will have to do the conversion to datetime just like you mentioned earlier

thanks you guys rocks!
you two seems pretty familiar with datatables, can bring in a off-topic?


answer if you like, if not, you still rocks! lol

@jason_Yao I’m not sure i understand why you need to use the datatable at all? It seems like you could just use a single for each statement to iterate through the mailmessages. It will get the message, read the attachment, do the processing, send a reply, then move to the next mailmessage until all have been dealt with.

I don’t believe you can store mailmessage objects in a datatable. It also seems like that is the only item in the datatable? If it’s the only item in the datatable, you should utilize a list, array, ienumerable, or any other collection instead.

1 Like

thanks for look into this dave! so yea, essentially, it’s looping thru the mails, collect the information from the those mail, and then send those data for processing on another server. as that server make progress the bot will update the status. eventually that status column will get updated to “complete”, and i need a way for the bot to reply that same email when it’s completed… and i dont really have a reliable way to get that specific mail, other than looping the emails again and find the exact match on subject. that could be a problem because there could be identical mail subjects out there. so i thought this whole thing would be a lot easier if i could store email objects in the datatable, and after a while when some of the email request are completed, i could just filter “complete” status and then send reply by looping thru that datatable…

Is it possible to iterate through the emails one at a time? Or is the processing on another server going to take too long? If you can wait, I would do as i mentioned before where everything is simply done in one for each loop.

Otherwise, you can use a dictionary to story the status of each mailmessage. The key would be the mailmessage, and the value would be the string (success/failure). I still don’t really see the point of storing the mailmessage in a list or datatable though. I just am having trouble understanding the process flow

yeah, the process on another server does take a while, so it wouldn’t make sense to loop one at a time. bcorrea, did point out unique message-id do exist, so i’m going to try to use that to identify email more reliably. so wish me luck :joy:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.