If Then Else Statement - If Time Falls Within 45 mins of Time Stamp on Excel Doc

Hi there. I’m still new to UiPath and stumbling through things a bit. :slight_smile:

I have a datatable that was pulled from a SQL query, then that data has been filtered and sorted by a specific column.

I need to check the most recent time stamp vs what the current system time is, and compare if the timestamp falls within the last 45 minutes of the current system time. That column format is “2/4/2020 16:02:20 PM”

Best route to go about that? If it falls within the 45 minutes of system time - then the robot will be done. If it doesn’t - then it will need to send an email (that part I’ve figured out on a previous email)

Thanks in advance!

@meggasaurus:

  1. sort (descending) datatable on date column - use Sort Data Table activity. Name (Header) of the column goes to the Name is the activity’s properties. You can also use column index (starts from 0).
  2. if now.AddMinutes(-45).ToString <= the top value in the sorted column, the value is with in the 45 minute range, else greater than 45 minutes

Sort Date Table: https://docs.uipath.com/activities/docs/sort-data-table

Hey @sumitd - sorry for the stupid questions but I’m not 100% understanding.

This is what I have currently:

flna1

flna2

flna3

flna5

flna4

DataBaseTime.AddMinutes(45) <= DateTime.UtcNow
Try to not do any time conversions to string…

So, I was able to get the rest of the activities set - its just the condition equation that I am working on for the else statement :

Convert.ToDouble(str_currentTime2)-Convert.ToDouble(str_RecentDropTime)>45

I don’t think that is correct though. It is comparing the current system time against a time stamp in an excel cell. I want to see if that time is within the last 45 minutes.

If it within the last 45 minutes, nothing will happen.

If it’s greater than 45 minutes - then it will send the email.

Any help?

@meggasaurus - don’t convert and subtract time.

Instead,
Now.AddMinutes(-45) >= str_RecentDropTime.
Yes = lies with in 45 minutes
No = before 45 minutes

@sumitd - It’s erroring - saying -

"Option Strict On Disallows implicit conversions from ‘String’ to ‘Date’.

Oh yes, you would to convert str_RecentDropTime to dateTime format.

Will have more details in a bit - in the middle of something.

Try this: Say, date in excel is: 2/4/2020 16:02:20 PM

DateTime.ParseExact(,“MM/dd/yyyy HH:MM:SS”, System.Globalization.CultureInfo.InvariantCulture)

And that will need to be in an assign activity or will I need to do that as the condition in the Try/Else/Then? Gonna try both but want to make sure I understand clearly.

@meggasaurus - in an if

Sorry for the stupid question but, in the current “If statement” - it needs to go between the str_currentDate=str_RecentDropDate and the Now.AddMinutes(-45)?

I tried to replace it in the current expression to this -

Now.AddMinutes(-45) >= DateTime.ParseExact(,“MM/dd/yyyy HH:MM:SS”, System.Globalization.CultureInfo.InvariantCulture)

and it’s giving me an error - "Argument no specified for parameter ‘s’ of ‘Public Shared Function ParseExact(s As String, format As String, provider As System.IFormatProvider) As Date’.

@meggasaurus I guess you need to use it in this way :

DateTime.ParseExact(str_RecentDropTime,“MM/dd/yyyy HH:MM:SS”, System.Globalization.CultureInfo.InvariantCulture)

@supermanPunch - so this worked! I am getting a System Arguement Null Exception in my output log though. That string reference not set to an instance of a string?

There was no email that was sent though saying it fell outside of the 45 minutes. Makin’ traction here!! :slight_smile:

@meggasaurus Can you tell me when do you get this error, Also can you send a Screenshot of the Workflow ?

It is getting an error during the 2nd IF statement -

And then the workflow -

debug4

@meggasaurus What’s the value in str_RecentDropTime ?

dt_RecentDropDate.Split(" "c)(1).ToString

The data is being pulled from the excel doc, and split up into the Date and the time for comparison. - I may need to do an Assign for that.

@meggasaurus Can you use this: dt_RecentDropDate.Split(" "c)(1).ToString, inside a message box and show me the value , I want to know how the value appears from that , if it’s really in a Format suitable for DateTime.Parse :sweat_smile:

@supermanPunch
Here you go:

Annotation 2020-02-12 090145