Get a date in formart "dd/mm/yyyy"

How can I get a specific date format? In my case dd/mm/yyyy"

I know that I could convet.toshortdatestring but I need that my variable will be a date not a string

6 Likes

@Lucky0906 Is this what you need? I didn’t noticed you didn’t wanted string.

now.Date

No, I didn’t I need the date type to make a comparison to other date

Your request doesn’t really make sense. A date only has a “format” when it is converted into string. Otherwise it is a date which can already be compared. The only conditions are the cultureinfo settings (i.e. if you try to compare a US date with a UK date they won’t match all the time! :D)

Please send an example .xaml file of what you are trying to do.

Richard

2 Likes

Hey @Lucky0906

If i am not assuming wrong here what you wants to achieve then please review the attached sample workflow and let me know :slight_smile:

Approaches can be many, here is the simplest one :slight_smile:

Dateinformatsample.xaml (6.3 KB)

and also you can check out this as well :slight_smile:

Regards…!!
Aksh

4 Likes

@Lucky0906,

You can use this - Convert.ToDateTime(dt.ToString(“dd/MM/yyyy”)), where dt is DateTime variable.

Regards
Madhura

7 Likes

To convert the datetime into a specific format use the below fomatiing:
DateTime.Now.ToString(“yyyyMMdd”, System.Globalization.CultureInfo.InvariantCulture)

8 Likes

I am using the data scraper wizard to get table values from a website and put it into a excel file.
My big problem is that UiPath gets the date fields in mm/dd/yyyy format but they are dd/mm/yyyy. How can I fix this? I dont know where to put Convert.ToDateTime(dt.ToString(“dd/MM/yyyy”)) into the data scraper.

3 Likes

@Bruno_Luan_Carvalho
It sounds like you said that on the website the dates are in “dd/mm/yyyy” format?
I think you need to treat it normally as a string and just write it in that format to Excel. You can change the default date format that your computer sees by going to Control Panel > Region and Language. Changing that setting will see the day and month in the correct spot.

However, if you don’t want to change your region and use the basic mm/dd format so you want to convert it then you would probably want to correct it line by line with a ForEach, or if you are processing each line one at a time you can do it within that loop.
You can use I believe
row(“Date”) = Date.ParseExact(“dd/mm/yyyy”,row(“Date”).ToString.Trim,System.Globalization.CultureInfo.InvariantCulture).ToString(“mm/dd/yyyy”)

You can also just treat it in reverse and reformat it like
row(“Date”) = CDate(row(“Date”).ToString.Trim).ToString(“dd/mm/yyyy”) which will flip the month to the date spot and date to the month spot

So in summary,
Either change your Default Regional Date Format for the computer or inside a ForEach reformat each date one by one.

There are also alternative ways with LINQ but was trying to be simple.

Regards.

4 Likes

Hi! Thank you for the response!

I managed to solve the problem inside the excel with vba, after the data scrapping.

Just to everybody with the same issue:
The big problem was that some dates imported as dd/mm and some as mm/dd. I realized that some of then were imported as text. Starting with this I wrote a macro that treated… used istext also used datevalue in the code.

Thanks again!

1 Like

Bruno,

Would you mind sharing the vba code you wrote?

I am attempting to keep only the date in a single cell and any code I attempt to write just does not seem to work.

Thank you!

1 Like

Hi @ksamsondad,
Use below code it will work.
Mention the what specific format of your input and what format you are expecting.
Date.ParseExact(“dd/mm/yyyy”,strDate.ToString.Trim,System.Globalization.CultureInfo.InvariantCulture).ToString(“mm/dd/yyyy”)

Or

CDate(strDate)

Regards,
Arivu

3 Likes

Hi All,
I got a bit problem in here.
I tried couple of codes about and they don’t work well in my case.
the date i scrapping from web like
04/03/1982
26/10/1972
4/03/1993
7/06/1985
8/02/1992
28/10/1993
24/10/1993
1/11/1991
31/07/1992

I tried
DateTime.Parse(Dob).ToString(“…”)
it works with the first one.
and when it comes to the second it will not work.
I tried.
Date.ParseExact(“dd/mm/yyyy”,Dob.ToString.Trim,System.Globalization.CultureInfo.InvariantCulture).ToString(“mm/dd/yyyy”)
however it will not work from the first one.
I also tried
CDate(Dob.ToString.Trim).ToString(“dd/mm/yyyy”)

seems work with the first one only.
Any advice.
Many thanks
Hung

Hey @hungdo,

In this case you need to use TryParseExact Method allowing the predicted formats as an array.
Refer this link and find the xaml for reference,

Note: You can convert any formats to your desired format.

Regards,
Dom :slight_smile:

5 Likes

DateTime.ParseExact("1/11/1991", "d/mm/yyyy", CultureInfo.InvariantCulture).ToString("mm/dd/yyyy")

Regards,
Arivu

2 Likes

may I ask what dose “System.Globalization.CultureInfo.InvariantCulture” means here?

Hi @Xiaoyu_Wang,

Namespace: System.Globalization

.NET Framework Class Library

CultureInfo.InvariantCulture Property

Refer this one

Regards,
Arivu

3 Likes

Hi @arivu96, there is a little mistake in your code, Argument 1 and Argument 2 need to be switched.
Best
Dieter

@ClaytonM
I tried to reverse date and month to reformat the date uisng **w(“Date”) = CDate(row(“Date”).ToString.Trim).ToString(“dd/mm/yyyy”) but it is giving month as 00
Eg :
Input -“03/22/2019”
Output -“22/00/2019”

Regards,
Shankar

2 Likes

Hi. Try using MM for month. Lowercase mm is for minutes.

Regards.

6 Likes