Convert string to date time

Hi , i extract from a pdf file a string which is in “dd/mm/yy” format and i would like to convert it into “dd/mm/yyyy”
i tried convert.ToDateTime(“13/03/19”).ToString(“MM/dd/yyyy”)
but i got the error : Conversion from string “24/10/18” to type ‘Date’ is not valid.

any help ?
thanks

Assign to a date variable: Convert.ToDateTime(dt.Rows(0)(“YourDate”).ToString).Date
DateTime.ParseExact(convertedDate.ToString(“dd/mm/yy”), “dd/mm/yy”, Nothing).ToString(“MM/dd/yyyy”)

5 Likes

Hi @grish

Use the below expression which convert 13/03/19 to 13/03/2019

Datetime.parseexact(“13/03/19”,“dd/MM/yy”,system.globalization.cultureinfo.invariantculture).ToString(“dd/MM/yyyy”)

The above returns a string, if you want Datetime then use Convert to datetime to the above expression

Convert.toDatetime(Datetime.parseexact(“13/03/19”,“dd/MM/yy”,system.globalization.cultureinfo.invariantculture).ToString(“dd/MM/yyyy”))

15 Likes

thanks guys

this one doesn’t work well. it says String was not recognized as a valid DateTime.

1 Like

Can you change daterecep to string, try passing the date directly and give a try

still the same error

you say that i should replace daterecep by “13/03/19” ?
even with this i have the same error

the other technique works but in excel it isn’t in cell format date, it’s in standard format

Why there is a space before Daterecep , remove the space

that’s weird because when i put daterecep at “10/03/19” it works but not for 13/03/19

Capture
and i don’t need the time behind. wtf ?

String are represented with format dd/MM/yyyy and datetime are represented as dd/MM/yyyy HH:mm:ss

Hi @grish,

As your string is “13/03/19” and you can change the format of the provided string using the below expression

output = Datetime.parseexact(“13/03/19”,“dd/MM/yy”,system.globalization.cultureinfo.invariantculture).ToString(“dd/MM/yyyy”)

The above output is a string, and the output is of format dd/MM/yyyy

To convert the above output to Datetime

Dateoutput=
Datetime.ParseExact(output,“dd/MM/yyyy”,system.globalization.cultureinfor.invariantculture)

The above output will be date time and the format of date time is dd/MM/yyyy HH:mm:ss

Now where r u using this output

2 Likes

my workflow is just composed with 2 assign and 1 write line
Daterecep <= “The date String”
out_DateRecep <= Datetime.parseexact(Daterecep,“dd/MM/yy”,system.globalization.cultureinfo.invariantculture).ToString(“dd/MM/yyyy”)

and i write out_datarecep.

the final objectif is to write that date on excel but with the date format (by now it is written with standard format)

Hi @grish,

To achieve this first take a sample excel sheet and have a column called Date and select the complete column and right click and format cells and go to category date and select the format dd-MM-yyyy for ex(14-03-2012)

Now refer the below workflow and write the output variable to the column under date

Main (1).xaml (16.1 KB)

Refer the sample excel file

new1234.xlsx (7.9 KB)

1 Like

i can’t have the right to modificate the excel sheet,
in my sheet i have 13/03/2019 00:00:00 visible on the cell but on the table i have #########
how can i seperate dd/MM/yyyy from hh:mm:ss ?

How you will achieve this, you will be using any activity that is write cell, but write cell accepts only string variables not datetime.

1 Like

Hey @grish You can try using substring function to seperate time from date.Capture

Regard’s ,
Suruchi.

1 Like

yeah you’re right, i’m f*cked :man_facepalming:

hi @suruchi120294,
what type is tdate ? because i am using dateTime and there isn’t .Substring() to that type

hi @grish,
Try with this one, first you convert the datetime to string and then you can use the “Substring” method to split the date.

Regard’s
Suruchi.