I have a variable of type string with this format “yyyy-MM-dd”
for example:
this is my variable
“2020-01-05”
and I want this to be my way out
“2020-01-31”
try this way but I get this error
how can I get the last day of the month according to my string type variable
thanks
If MyStr
is your original string formatted as “yyyy-MM-dd”, then assign a variable (can even be the same one if you want to overwrite it) to:
Date.ParseExact(MyStr, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture).AddMonths(1).AddDays(-1*Date.ParseExact(MyStr, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture).Day).ToString("yyyy-MM-dd")
1 Like
It works fine, just a question, I get it in this format, how could I remove the timestamp and format “yyyy-MM-dd”
My variable containing this value is type generic value
I made an addendum to my original post. If you end the statement with ToString("yyyy-MM-dd")
, you’ll get a string only containing the date and not the time.
Anthony_Humphries:
Date.ParseExact(MyStr, “yyyy-MM-dd”, System.Globalization.CultureInfo.InvariantCulture).AddMonths(1).AddDays(-1*Date.ParseExact(MyStr, “yyyy-MM-dd”, System.Globalization.CultureInfo.InvariantCulture).Day).ToString(“yyyy-MM-dd”)
I tried it and it worked perfectly thanks
system
(system)
Closed
April 2, 2020, 7:53pm
6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.