Date Formatting in C#

4.43 (131 votes)

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:
Last Updated:
Posted by:
Total Views to date: 229710


- Navi

this is very usefull...

- Pratul

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

- bharath

nice information.tnx

- stephen

Nice piece of info.. thanks a lot

- Carsten

Perfect - exactly what i needed..

- Krishnaraj

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

- 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");

- da programmer

This Is The Shieeet

meghci boku

- Jude Love

thanks dude

- Anil

This is very useful.

- Nilay


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

- dotJupiter

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

- sabit

useful information about datetime format!!!

- Sabit

useful information

- Jezzrel

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

- nitesh

This is very useful.

- Muktadir


- sam


- Prasun Chatterjee

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

- 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.

- Navina

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

- Shreyas

Good one...Thanks..

- Mayur


- sandeep sharma


Thanks !!

- vikas


- 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...

- Mike


The "d" option (short date) is culture specific. Leading zeros are omitted if your culture is en-US. They are retained for en-GB.

- Jomon John

It's good.
Thank you....

- suhas


- Abolfazl RoshanZamir

very informative... thanks for sharing sir...

- akil

i need date format "mmm yyyy". Ex : Mar 2015, what is the specifier ??

- Mike


You need capital Ms: "MMM yyyy"

DateTime.Now.ToString("MMM yyyy")

- Andreas

Helpful article!

Is there any option to display the date format as days since 01/01/1900

e.g. 21/08/2015 as 42237

Thanks in advance.

- Pramod Gagare


Recent Comments

Rajasekar 24/11/2015 12:27
In response to Import Data From Excel to Access with ASP.NET
While use this code i'm facing on error: "Unrecognized Database format C:\mydabase.accdb" can any...

Parmod 24/11/2015 07:28
In response to ASP.NET 5 Project Basics
For a new learner (Fresher) in ASP.NET there is a issue Fresher have to learn two types of , old...

Robert 22/11/2015 21:35
In response to ASP.NET 5 By Numbers
I have to agree fully with Paul, this does sound like an entire mis-mash of technologies. Sort of in...

Christian 21/11/2015 15:46
In response to MVC 5 with EF 6 in Visual Basic - Creating an Entity Framework Data Model
Many thanks Mike to introduce me in the EF6 Code First way of thinking. Exactly what I need for my...

ax plains 20/11/2015 16:29
In response to Examining the Details and Delete Methods
Hello, really great tutorial for a beginner like me! Is it possible to have an explanation on how a...

Abdul Latif 20/11/2015 14:42
In response to Reading Excel Files Without Saving To Disk In ASP.NET
Could anyone please help me, I am getting : "OfficeOpenXml.ExcelPackage" does not contain a for...

Thomas 20/11/2015 09:44
In response to Cheat Sheet - .NET Framework Exceptions
Hey Mike, nice list. I've also checked your article on how you created the list, but is there any to...

Pramod Gagare 19/11/2015 11:18
In response to Date Formatting in C#

Robby 19/11/2015 08:16
In response to WebMatrix - Database Helpers for IN Clauses
Would it also be possible to override the default query and querysingle methods to include the azure...

Menja 18/11/2015 08:28
In response to Sessions and Shopping Carts
Thank you for a perfect description and that you show all the screenshot at the same time!!! It a...