How to get current date in 'YYYY-MM-DD' format in ASP.NET ?
How to get current date in 'YYYY-MM-DD' format in ASP.NET?
How to get the current date for what? What are you using the date for will you be displaying it. Is it just for one field or multiple fields. It would be a good idea to elaborate a little more. –
Blum
Which WebControl are you using? Did you try?
DateTime.Now.ToString("yyyy-MM-dd");
leave off the semicolon for VB.NET ;) –
Startle
if anyone need some more references i suggest to read and follow the tips over here : dotnetperls.com/datetime-format-vbnet –
Scutcheon
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
If you post code, XML or data samples, please highlight those lines in the text editor and click on the "code samples" button (
{ }
) on the editor toolbar to nicely format and syntax highlight it! –
Unutterable 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
© 2022 - 2024 — McMap. All rights reserved.