Date Formatting in C#

Cheat sheet detailing formatting options for dates and times in C#.

Example Usage

<%= String.Format("{specifier}", DateTime.Now) %>

Specifier Description Output
d Short Date 08/04/2007
D Long Date 08 April 2007
t Short Time 21:08
T Long Time 21:08:59
f Full date and time 08 April 2007 21:08
F Full date and time (long) 08 April 2007 21:08:59
g Default date and time 08/04/2007 21:08
G Default date and time (long) 08/04/2007 21:08:59
M Day / Month 08 April
r RFC1123 date Sun, 08 Apr 2007 21:08:59 GMT
s Sortable date/time 2007-04-08T21:08:59
u Universal time, local timezone 2007-04-08 21:08:59Z
Y Month / Year April 2007
dd Day 08
ddd Short Day Name Sun
dddd Full Day Name Sunday
hh 2 digit hour 09
HH 2 digit hour (24 hour) 21
mm 2 digit minute 08
MM Month 04
MMM Short Month name Apr
MMMM Month name April
ss seconds 59
fff milliseconds 120
FFF milliseconds without trailing zero 12
yy 2 digit year 07
yyyy 4 digit year 2007
: Hours, minutes, seconds separator, e.g. {0:hh:mm:ss} 09:08:59
/ Year, month , day separator, e.g. {0:dd/MM/yyyy} 08/04/2007
. milliseconds separator  

Date Posted: Sunday, April 8, 2007 9:11 PM
Last Updated: Wednesday, October 23, 2013 1:43 PM
Posted by: Mikesdotnetting
Total Views to date: 188137


Friday, April 10, 2009 11:19 AM - Navi

this is very usefull...

Wednesday, April 15, 2009 10:02 AM - Pratul

Gr8 !! Gr8 !!, this is what exactly I was searching !
Thank you very much.

Friday, April 24, 2009 10:24 AM - bharath

nice information.tnx

Thursday, June 4, 2009 7:32 AM - stephen

Nice piece of info.. thanks a lot

Wednesday, July 22, 2009 10:58 AM - Carsten

Perfect - exactly what i needed..

Wednesday, December 16, 2009 10:27 AM - Krishnaraj

Nice piece of quick information. Thank you, saved my time

Wednesday, March 10, 2010 12:04 PM - Ric

You might also want to mention that the formatting is available through the .toString() method as well as the string.Format one.

DateTime dt = new DateTime();
string formattedDate = dt.toString("dd/MM/yyyy");

Thursday, June 3, 2010 9:56 AM - da programmer

This Is The Shieeet

meghci boku

Thursday, June 24, 2010 6:25 AM - Jude Love

thanks dude

Friday, August 27, 2010 6:17 AM - Anil

This is very useful.

Thursday, September 23, 2010 4:25 PM - Nilay


I was looking for that in MSDN & it was too much information in it. This one is good.

Tuesday, June 7, 2011 6:57 AM - dotJupiter

Great article. It summarizes all the parameters that I have been looking for a long time.

Friday, March 30, 2012 5:09 PM - sabit

useful information about datetime format!!!

Friday, March 30, 2012 5:11 PM - Sabit

useful information

Tuesday, May 15, 2012 8:54 AM - Jezzrel

Yes, nice one. It's very useful...

Friday, June 1, 2012 2:11 PM - nitesh

This is very useful.

Sunday, July 1, 2012 11:41 AM - Muktadir


Tuesday, January 8, 2013 4:12 AM - sam


Wednesday, January 16, 2013 6:00 AM - Prasun Chatterjee

Great article.Thanks. But what if I need something like 2nd January,2013??
Thanks in advance.

Thursday, January 17, 2013 8:03 AM - Mike


You will have to write your own method to generate the ordinal suffix based on the date, and then build your own string using that. There is no short cut formatter for what you want that I know of.

Wednesday, July 10, 2013 3:03 PM - Navina

tnks 4 ur info..
quite interesting....!

Wednesday, August 14, 2013 10:52 AM - Shreyas

Good one...Thanks..

Wednesday, October 30, 2013 11:34 AM - Mayur


Thursday, April 24, 2014 12:28 PM - sandeep sharma


Thanks !!

Saturday, May 31, 2014 8:39 AM - vikas


Tuesday, September 30, 2014 1:56 PM - Bob Rodes

The short date option (d) doesn't include leading zeros in month and day, so it would actually render 8/4/2007. To get the leading zeros the format needs to be spelled out: MM/dd/yyyy or dd/MM/yyyy. has all the formats you never use...

Wednesday, November 12, 2014 10:56 AM - Jomon John

It's good.
Thank you....
Add your comment

If you have any comments to make about this article, please use this form to do so. Make sure that your comment relates specifically to the article above. More general comments can be posted through the form on the Contact page.

Please note, all comments are moderated, and some may not be published. The kind of things that will ensure your comment is deleted without ever seeing the light of day are as follows:

  • Not relevant to the article
  • Gratuitous links to your own site or product
  • Anything abusive or libellous
  • Spam
  • Anything in a language I don't understand including gibberish.

I do not pass email addresses on to spammers, so a valid one will assist me in responding to you personally if required.

Recent Comments

stephen 1/28/2015 9:53 PM
In response to ASP.NET MVC 5 with EF 6 - Working With Files
Hi, Sorry for wasting your time, I had a comment <!--Images--> inside the form this stopped it from...

stephen 1/28/2015 9:47 PM
In response to ASP.NET MVC 5 with EF 6 - Working With Files
Everything has been ok up until this part, here's a snippet of the entire file but i removed lines =...

Stephen kenny 1/28/2015 8:26 PM
In response to ASP.NET MVC 5 with EF 6 - Working With Files
Hi, great article. My issue is with the create view. @using (Html.BeginForm("Create", "Reptiles",...

Jenelyn 1/27/2015 6:44 PM
In response to MVC 5 with EF 6 in Visual Basic - Implementing Basic CRUD Functionality
I'm searching CRUD using 2010 and I can't find any, how sad...

Kadu Portugal 1/23/2015 10:55 AM
In response to Scheduled Tasks In ASP.NET With Quartz.Net
Hi Mike, Thank you for your useful article. I implement it in my project, and everything run...

Satyabrata 1/23/2015 6:02 AM
In response to Usage of the @ (at) sign in ASP.NET
Refreshed a lot of things.Thanks...

Vo Thanh Chinh Trung 1/22/2015 4:30 PM
In response to Adding A View
It's very helpful...Thank you so much, Mikes!...

Joop Stringer 1/22/2015 12:00 PM
In response to Inline Editing With The WebGrid
How to add a row for a new record ?...

Gaetan C 1/21/2015 8:49 PM
In response to Looking At The WebMatrix WebGrid
I use the webgrid very often and I Wonder if it's possible to merge to different sql query into on...

Teresa 1/19/2015 3:08 PM
In response to MVC 5 with EF 6 in Visual Basic - Creating an Entity Framework Data Model
At the top, the first thing you write is "Open Visual Studio and create a new C# Web project named I...