Convert to Date Time From String

Hi Everyone,

I want to convert dates in general format to Date Time format in Excel. How can I do this? I read Excel with Read Range and converted it to Datatable. Later, when I convert to String and ConvertToDateTime, I get the following error.


image

Check these threads:

Hi @nilesay

You try to convert the Date

YourString → 22/09/2022

DateTime.ParseExact(YourString,"dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")

Output → 09/22/2022

Regards
Gokul

Hi @nilesay

You can try with this expression

You need check what format did the datetime variable returning by DateTimevar.Tostring and the convert them with this expression

DateTime.ParseExact("DateTimeVar.ToString",{"MM/dd/yyyy hh:mm:ss","dd/MM/yyyy hh:mm:ss"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString("dd.MM.yyyy")

In the expression inside {} you can give whatever format but the format which it is returning in the previous step when you checked is the must format because it going to use that format and then it will convert to another format which you will give

Regards
Sudharsan

When I substitute this statement in the second assign activity, I get the following error.

@nilesay

son_date must be a string variable

Regards
Sudharsan

You need to convert the string to Date Time?

If yes try this

CDate(date_time)
or
Convert.ToDateTime(date_time)

Regards
Sudharsan

Hi @nilesay

How about this expression?

CDate(DateTime.ParseExact(date_time,"dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy"))

Regards
Gokul

Hi @Sudharsan_Ka ,

I get the following error when I make ‘son_date’ variable String.
image

Try this @nilesay

Hi @Gokul001 ,

when I make ‘son_date’ variable DateTime still this error “Assign: String was not recognized as a valid DateTime.” and when ‘son_date’ variable type is String I get the following error.

Can you change the log message above to .ToString instead of .GetType and share the scrren shot

Hey share the sample input and expected output @nilesay

@nilesay
Try this

DateTime.ParseExact(date_time,"MM/dd/yyyy HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture).ToString("MMM dd yyyy")

Hi @Sudharsan_Ka ,

If this is what you want here, first row output the log message
image

Try this

DateTime.ParseExact(date_time,"dd.MM.yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")
1 Like

@nilesay

You need to change the column type to date in excel right?
you can achieve it using a modern activity or BalaReva Activity

Check out this image and skeleton xaml file for modern

Sequence.xaml (8.2 KB)

Checkout this thread for Balareva activities

Regards
Sudharsan

2 Likes

Hi @Gokul_Jayakumar ,

It works, thank you!

Hi @Sudharsan_Ka ,

Thank you.

Regards,

1 Like

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