Assign - String was not recognized as a valid DateTime

I am trying to convert a string to DateTime, MM/dd/yyyy, and get the month, however, I am getting the error

Assign - String was not recognized as a valid DateTime.

This is the string it cannot convert “04/30/2022”.

My code:

MonthName(Convert.ToInt32(Date.ParseExact(CurrentRow("Due Date").ToString,"MM/dd/yy",CultureInfo.InvariantCulture).ToString("MM"))).ToString

Hi @Nelson.R

You have missed yy in the expression

MonthName(Convert.ToInt32(Date.ParseExact(CurrentRow(“Due Date”).ToString,“MM/dd/yyyy”,CultureInfo.InvariantCulture).ToString(“MM”))).ToString

Try this

Regards
Sudharsan

1 Like

You’re overcomplicating it.

DateTime.Parse(“04/30/2022”).ToString(“MMMM”)

image

Actually yes :joy:

Date.ParseExact(CurrentRow(“Due Date”).ToString,“MM/dd/yyyy”,CultureInfo.InvariantCulture).ToString(“MMMM”)

This will also do @Nelson.R

Regards
Sudharsan

2 Likes

If the date string is standard MM/dd/yyyy you don’t need ParseExact and all that extra stuff. Datetime.Parse just uses your system format.

1 Like

Ohh Okay @postwick

1 Like

what about this CDate("04/30/2022").ToString("MMMM")
with this you have 9 less chars to type :rofl: :laughing: (just having fun)

just trying to dive into “who can write least possible code for same result”

2 Likes

Thanks. When reviewing all my data some dates had a different date format so I had to make changes somewhere else in my code to keep a single format for all the dates.

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