Date conversion Error in mvc

Posted by Klbaiju under ASP.NET MVC on 6/13/2018 | Points: 10 | Views : 68 | Status : [Member] | Replies : 1
Hi,

I want to convert date in 'yyyy-mm-dd' format

following is my code

string currentYear = DateTime.Now.Year.ToString();
string Cmonth = DateTime.Now.ToString("MMMMMMMMM");
string smonth = DateTime.Now.Month.ToString();
string kk = currentYear + "-" + smonth + "-" + "01";

DateTime s = Convert.ToDateTime(kk);

when I execute above code Iam getting s as

6/1/2018 12:00:00 AM

my requirement is s should be

2018-06-01

how it is possible

Regards

Baiju




Responses

Posted by: Sheonarayan on: 6/15/2018 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Write

s.ToString("yyyy-MM-dd");


It should work.

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response