Convert DateTime to String

DateTime date_1 = 01/30/2024 00:00:00

Desired output str_1 = Jan 30, 2024 (string variable)

Please advise

Hey @shrishti.diggikar
you can use ToString method:
yourDateTimeVariable.ToString(“MMM dd, yyyy”)

image
image

Hi @shrishti.diggikar

- Assign -> str_1 = date_1.ToString("MMM dd, yyyy")

Check the below workflow for better understanding,

Hope it helps!!

Here are all the options you can use for .ToString on a datetime. Scroll down to the format specifier table.

image
I’m getting this error. Can you please advise what could be the reason?

please use the immediate panel

type in the following statements:
startDate
startDate.GetType()

and share a screenshot of the outcomes with us. Thanks

can you use the immediate panel (highly recommended to work with and really usefull for quick rnd and prototyping)

startDate.ToString("MMM dd, yyyy")

From our end a screenshot
grafik

image
Thanks @ppr for detailed explanation!

try
CDate(CurrentRow("Start Date").toString().Trim).ToString("MMM dd, yyyy")

This worked for me!

DirectCast(CurrentRow(“Start Date”), DateTime).ToString(“MMM d, yyyy”)

1 Like

its just a variation of the conversion

just for the info:
grafik
CurrentRow is of DataType: DataRow
The Column Values are within the ItemArray which is an Object Array


it will return a DateTime as more generic DataType: Object (that why we got the error from above, because the Object DataType cannot handle a ToString() along with a format string like MMM dd, yyyy)

So we have several methods to get proper returned datetime which we can format later:
grafik

or we are going further to approaches like
grafik

1 Like

Thanks for pointing that out! Super helpful in future projects!

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