String convertTo DateTime

Hi People,

Str_Date = “09-06-1997” i want to convert into Dateformat the variable type should be System.DateTime

i got output when i use this expression Convert.ToDateTime(Str_Date)------> 09/06/1997 00:00:00

i want output only date = 09/06/1997

Hi @Hari_Krishnan2

Str_Date = "09-06-1997"
DateTime.ParseExact(Str_Date, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("dd/MM/yyyy")

Cheers!!

Hi @Hari_Krishnan2

Str_Date = "09-06-1997"

Output = DateTime.ParseExact(Str_Date,"dd-MM-yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")

Regards

Hi @Hari_Krishnan2

Str_Date = "09-06-1997"

Output = DateTime.ParseExact(Str_Date,"dd-MM-yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")

OR the below simple syntax should also work:

Str_Date = "09-06-1997"

Output = Convert.ToDateTime(Str_Date).ToString("MM/dd/yyyy")

Regards

@Hari_Krishnan2

The problem here is i want store into datetime variable Type like,

Variable name |||||||||| Variable type
Date ||||||| DateTime

I’m getting below error,

Argument ‘Value’: BC30512: Option Strict On disallows implicit conversions from ‘String’ to ‘Date’. The selected value is incompatible with the property type.

Hi @Hari_Krishnan2

If you want to convert a datetime from a particular format to another format you can’t stpre that in DateTime variable. If you store that in DateTime Vairable you will getting the time stamp. By the way where will you be using the converted Date? Please specify

Regards

Hi @Hari_Krishnan2

If you want to convert a datetime from a particular format to another format you can’t stpre that in DateTime variable. If you store that in DateTime Vairable you will getting the time stamp. By the way where will you be using the converted Date? Please specify

Regards

my ultimate goal is i want only the date i don’t want 00:00:00

Hi @Hari_Krishnan2

If you want to store the output in a dateTime variable you can’t avoid that timestamp. To Avoid the timestamp you need to convert that to String variable, then only it’s possible its not possible in DateTime variable.

Regards

1 Like

@vrdabberu

is there any variable available like dateonly???

Hare Krishna,

DateTime.ParseExact(YourVariable, “dd/MM/yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)

This will surely work for you.
Please let me know if solved.
Radhe Radhe

1 Like

Try this : DateTime.ParseExact(YourVariable, “dd/MM/yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)


In first image you can see the exact syntax which will help you out
&
In second image you can see the desired output.

Thank you.
Happy Automation.

1 Like

Hi @hrishikesh.k

There is variable type DateOnly but if you want only MM/dd/yyyy then the variable type should be System.String.

Regards

Hello
DateOnly is just a variable scope.

Given query works Effort Lessly.

Please change variable type to “string”
and apply given query.

To get only the date part in the format dd/MM/yyyy from a DateTime object in UiPath, you can use the .ToString method with the appropriate format specifier. Here’s how you can do it:

Str_Date = “09-06-1997”
DateTime_Obj = DateTime.ParseExact(Str_Date, “dd-MM-yyyy”, System.Globalization.CultureInfo.InvariantCulture)
Output_Date = DateTime_Obj.ToString(“dd/MM/yyyy”)

Hi @Hari_Krishnan2

The below should give you a desired output of what you need
Str_Date = "09-06-1997"

Output = Convert.ToDateTime(Str_Date).ToString("MM/dd/yyyy")

Regards

Hi @Hari_Krishnan2

str_date : “09-06-1997”

Covert_Date : CDate(str_date).tostring(dd/MM/yyyy)

Hi @Hari_Krishnan2

There is an activity which directly converts without writing any expression
the name of the activity is “Extract Date and Time from Text”

In the properties panel of this activity set the Localization code to English(World)
and in the format tab you can select in which form you want your date or time

Hope this helps you