Convert System.string to System.datetime variable type

Hi all,

Current time and end time are in the string format but need to convert it to date time format.
Current time is system date time where as the end date is taken from excel its in string format.
Used Convert.Todatetime but its showing in 06/10/2023 03:44:00.
Format getting as expected but the variable type is string need to convert to datetime.
How to do this please help.
Extracted data - Copy.xlsx (8.1 KB)

Sequence_dateTime.xaml (10.6 KB)


Try this

endDate = DateTime.ParseExact(endDateString, “MM/dd/yyyy HH:mm:ss”, System.Globalization.CultureInfo.InvariantCulture)

Current time= DateTime.ParseExact(CurrenttimeString, “MM/dd/yyyy HH:mm:ss”, System.Globalization.CultureInfo.InvariantCulture)

@lrtetala ,Date time format = dd-MM-yyyy hh:mm tt
I’m getting in string type but need in datetime type.

Hi ,

Could you check with the below Expression :

DateTime.ParseExact("06-10-2023 03:44 PM","dd-MM-yyyy hh:mm tt",System.Globalization.CultureInfo.InvariantCulture)


It is in date time format check this

DateTime.ParseExact(Current_date, "dd-MM-yyyy hh:mm tt", System.Globalization.CultureInfo.InvariantCulture)

@supermanPunch ,
Wanted in datetime data type and the format should be dd-MM-yyyy hh:mm tt
I am getting proper format in string data type but the data type has to be datetime variable type

DateTime.ParseExact(dateString, "dd-MM-yyyy hh:mm tt", CultureInfo.InvariantCulture)

Hope it helps

Please check on this (76.0 KB)

Hope this helps!!

@supriya117 ,
getting in this format
Wanted in image
this format

Getting in this format, wanted in

Try this:

DateTime.ParseExact(dateString, "dd-MM-yyyy h:mm tt", System.Globalization.CultureInfo.InvariantCulture).ToString("dd-MM-yyyy hh:mm tt")

The output DataType will be System.String

Hope it helps!!

@Parvathy , I am getting the output in System.String System.DateTime.Now.ToString("dd-MM-yyyy hh:mm tt") by using this.
But wanted in System.DateTime


you can try this

DateTime.ParseExact(CurrentRow(0).ToString, "dd-MM-yyyy h:mm tt", System.Globalization.CultureInfo.InvariantCulture)

i have taken assign activity and variable type is system.datetime

let me know its working or not for you

@Praveen_Mudhiraj ,

System.datetime is correct but the date format should be in this form.
“dd-MM-yyyy hh:mm tt” = format
System.dateTime = variable type ,

Could you let us know what is the End Output that you require ? Are you storing this data in Excel and you want to represent it in the mentioned format ?

Do note that DateTime types is a Date type and it will inherently have no format or will have the one format in its DateTime type, and if we would require it to be in custom format, we convert it using .ToString() where the data type changes to String.


Assign: Current_date=System.DateTime.Now.ToString("dd-MM-yyyy hh:mm tt")  DataType:String
Assign:CurrentDateFormat=DateTime.ParseExact(Current_date, "dd-MM-yyyy hh:mm tt", System.Globalization.CultureInfo.InvariantCulture)  DataType:System.DateTime
Assign:FinalTime=CurrentDateFormat.ToString("dd-MM-yyyy hh:mm tt")  DataType:String

Hope this helps!!

@supermanPunch ,
Sequence_dateTime.xaml (10.6 KB)

In this workflow
Current_date and End_date are in string variable type.
Getting output proper format but the variable type should be dateTime.

“MM/dd/yyyy HH:mm:ss” this is a datetime format
“MM/dd/yyyy hh:mm tt” this is a custom datetime format

You will only get “MM/dd/yyyy HH:mm:ss” this format in datetime variable. By using this variable, you will able to change into other custom formats like “MM/dd/yyyy hh:mm tt” but can only storable in a string variable.

Hope it helps.

When you work with date and time values, you store the date and time values in a DateTime variable. The DateTime variable stores the actual date and time data, not the format.

You can format the DateTime variable as a string using a custom format like “MM/dd/yyyy hh:mm tt” when you need to display or output it. The formatted result is a string, not a DateTime variable, and you store it in a string variable.