Might be worthwhile using the CultureInfo to apply DateTime formatting throughout the website. Insteado f running around formatting whever you have to.
CultureInfo.CurrentUICulture.DateTimeFormat.SetAllDateTimePatterns( ...
or
CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";
Code should go somewhere in your Global.asax file
protected void Application_Start(){ ...
var formatedDate = DateTime.Now.ToString("yyyy-MM-dd",System.Globalization.CultureInfo.InvariantCulture);
To ensure the user's local settings don't affect it
<%= DateTime.Now.ToString("yyyy-MM-dd") %>
<%: DateTime.Today.ToShortDateString() %>
try ToString method for your desirer format use
DateTime.Now.ToString("yyyy-MM-dd");
OR you can use it with your variable of DateTime type
dt.ToString("yyyy-MM-dd");
where dt is a DateTime variable
Source: Stackoverflow.com