Nelson.R
(Randell Persad)
June 24, 2022, 2:50pm
1
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
postwick
(Paul Ostwick)
June 24, 2022, 3:06pm
3
You’re overcomplicating it.
DateTime.Parse(“04/30/2022”).ToString(“MMMM”)
2 Likes
Actually yes
Date.ParseExact(CurrentRow(“Due Date”).ToString,“MM/dd/yyyy”,CultureInfo.InvariantCulture).ToString(“MMMM”)
This will also do @Nelson.R
Regards
Sudharsan
2 Likes
postwick
(Paul Ostwick)
June 24, 2022, 3:15pm
5
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
what about this CDate("04/30/2022").ToString("MMMM")
with this you have 9 less chars to type (just having fun)
just trying to dive into “who can write least possible code for same result”
3 Likes
Nelson.R
(Randell Persad)
June 24, 2022, 6:02pm
8
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.
system
(system)
Closed
June 27, 2022, 6:02pm
9
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.