Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format 2010-11-24 date in C#?

Tags:

c#

asp.net

I am using

((DateTime)newsItem.Date).ToString(@"yyyy MM dd") 

which gives me 2010 11 24 but not 2010-11-24.

I want dashes in between the numbers of date.

like image 646
code master Avatar asked Nov 24 '10 08:11

code master


1 Answers

Have you tried

((DateTime)newsItem.Date).ToString(@"yyyy-MM-dd");

Also, since you format the time part away anyway in the ToString, you don't need to add .Date, and you can change it to

((DateTime)newsItem).ToString(@"yyyy-MM-dd");
like image 120
Øyvind Bråthen Avatar answered Oct 02 '22 20:10

Øyvind Bråthen