Changing Excel General Format to Date Format

Hey everyone. Working on my first big project.

One of the first things I need to do is get a csv cell of data into a workable date format because I am going to need to compare it to today’s date.

The cell has a format of 2019-12-30. I have been reading different things but am still unsure how I get this field into my project where I can compare to today’s date. Basically I need to see if the value is equal to today’s date minus one day.

Appreciate any help. Thanks

If in your excel sheet the values are formatted as Dates then when your DataTable will also be like that and ready to use, begin your tests by reading the range and evaluating that :slight_smile:

It’s a csv file so the cell formatting is General. I am guessing I would need to format it to date format before reading it from the data table?

Yes, you’ll need to convert it to a Date type within UiPath.

You can do that by using Convert.ToDateTime(variableHere)

@Jarzzz thank you, that was very simple to get me on the right track. It converted and included the time. Wasn’t sure how to remove that part. Tried a couple examples but didn’t work. Crazy how many different posts on this subject and so many different ways to do it. It’s confusing!

From the csv I have pdate which is a string in the format 2019-12-30. I found parsing in the documentation and thought I understood that to convert I would need another variable so I created pdate_new as string.

I tried this code but still getting an error. I am using Assign Activity
“String was not recognized as a valid DateTime”

pdate_new=DateTime.ParseExact(pdate,“yyyy-MM-dd”,System.Globalization.CultureInfo.InvariantCulture).ToString(“MM/dd/yyyy”)

Am I on the right track? Trying to get to 12/30/2019

Thank you!

1 Like

Try this =D

Assign pdate_new = `Convert.ToDateTime(pdate)’


Condition (Date.Today >= Convert.ToDateTime(pdate)) would return true if Todays Date is greater/equal to pdate

from here if you got that error, look into pdate variable, maybe an extra white space…

On the date part I am getting the date using:

pdate_new=Convert.ToDateTime(pdate).ToString

I am still getting with the hh:mm:ss ie 12/30/19 00:00:00

If you are trying to output it as a string without the time
pdate_new = Convert.ToDateTime(pdate).ToShortDateString


“Basically I need to see if the value is equal to today’s date minus one day.”

To achieve this use this condition statement…
If ( Date.Today.AddDays(-1).Equals(Convert.ToDateTime(pdate)) )

image

1 Like

@Jarzzz thank you very very much for your easy to understand examples! I have everything working. I ended up using this for my date comparison, “Date.Today > Convert.ToDateTime(pdate_new)”

I will get A LOT of use out if this set of code. Thanks again!

1 Like

You’re welcome! Happy developing :slightly_smiling_face: :upside_down_face:

Just as an added understanding, this will work only as long as the robot system time format is the same as in your csv file… the best to be sure is to use the ParseExact method…

I understand what you are saying. But in theory since your converting a time found in the CSV on the robot system, wouldn’t the converted and the current be in the same format?

Well i live in Brazil, so i come up with these types of problems all the time, since most servers are installed in English and very often carry USA format, so in my case if you send Convert.ToDateTime(“2019-12-30”) the conversion will be ok, but in case i run on a Brazilian format server, then i will get an conversion error cause system will use 30 as a month number… parseexact exists to force a format to work despite of the current system format…

2 Likes

@bcorrea Good to know :smiley:

1 Like

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