C# DateTime Format
Date and Time in C# are handled by the DateTime class in C#, which provides properties and methods to format dates in different datetime formats. This article blog explains how to work with date and time format in C#.
The following table describes various C# DateTime formats and their results. Here we see all the patterns of the C# DateTime, format, and results.
| Format |
Result |
| DateTime.Now.ToString("MM/dd/yyyy") |
05/29/2015 |
| DateTime.Now.ToString("dddd, dd MMMM yyyy") |
Friday, 29 May 2015 |
| DateTime.Now.ToString("dddd, dd MMMM yyyy") |
Friday, 29 May 2015 05:50 |
| DateTime.Now.ToString("dddd, dd MMMM yyyy") |
Friday, 29 May 2015 05:50 AM |
| DateTime.Now.ToString("dddd, dd MMMM yyyy") |
Friday, 29 May 2015 5:50 |
| DateTime.Now.ToString("dddd, dd MMMM yyyy") |
Friday, 29 May 2015 5:50 AM |
| DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm:ss") |
Friday, 29 May 2015 05:50:06 |
| DateTime.Now.ToString("MM/dd/yyyy HH:mm") |
05/29/2015 05:50 |
| DateTime.Now.ToString("MM/dd/yyyy hh:mm tt") |
05/29/2015 05:50 AM |
| DateTime.Now.ToString("MM/dd/yyyy H:mm") |
05/29/2015 5:50 |
| DateTime.Now.ToString("MM/dd/yyyy h:mm tt") |
05/29/2015 5:50 AM |
| DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") |
05/29/2015 05:50:06 |
| DateTime.Now.ToString("MMMM dd") |
May 29 |
| DateTime.Now.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss.fffffffK") |
2015-05-16T05:50:06.7199222-04:00 |
| DateTime.Now.ToString("ddd, dd MMM yyy HH’:’mm’:’ss ‘GMT’") |
Fri, 16 May 2015 05:50:06 GMT |
| DateTime.Now.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss") |
2015-05-16T05:50:06 |
| DateTime.Now.ToString("HH:mm") |
05:50 |
| DateTime.Now.ToString("hh:mm tt") |
05:50 AM |
| DateTime.Now.ToString("H:mm") |
5:50 |
| DateTime.Now.ToString("h:mm tt") |
5:50 AM |
| DateTime.Now.ToString("HH:mm:ss") |
05:50:06 |
| DateTime.Now.ToString("yyyy MMMM") |
2015 May |
- d: Represents the day of the month as a number from 1 through 31.
- dd: Represents the day of the month as a number from 01 through 31.
- ddd: Represents the abbreviated name of the day (Mon, Tues, Wed, etc).
- dddd: Represents the full name of the day (Monday, Tuesday, etc).
- h: 12-hour clock hour (e.g. 4).
- hh: 12-hour clock, with a leading 0 (e.g. 06)
- H: 24-hour clock hour (e.g. 15)
- HH: 24-hour clock hour, with a leading 0 (e.g. 22)
- m: Minutes
- mm: Minutes with a leading zero
- M: Month number(eg.3)
- MM: Month number with leading zero(eg.04)
- MMM: Abbreviated Month Name (e.g. Dec)
- MMMM: Full month name (e.g. December)
- s: Seconds
- ss: Seconds with leading zero
- t: Abbreviated AM / PM (e.g. A or P)
- tt: AM / PM (e.g. AM or PM
- y: Year, no leading zero (e.g. 2015 would be 15)
- yy: Year, leading zero (e.g. 2015 would be 015)
- yyy: Year, (e.g. 2015)
- yyyy: Year, (e.g. 2015)
- K: Represents the time zone information of a date and time value (e.g. +05:00)
- z: With DateTime values represent the signed offset of the local operating system's time zone from
Coordinated Universal Time (UTC), measured in hours. (e.g. +6)
- zz: As z, but with leading zero (e.g. +06)
- zzz: With DateTime values represents the signed offset of the local operating system's time zone from UTC, measured in hours and minutes. (e.g. +06:00)
- f: Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value.
- ff: Represents the two most significant digits of the second's fraction in date and time
- fff: Represents the three most significant digits of the second's fraction; that is, it represents the milliseconds in a date and time value.
- ffff: Represents the four most significant digits of the second's fraction; that is, it represents the ten-thousandths of a second in a date and time value. While it is possible to display the ten thousandths of a second component of a time value, that value may not be meaningful.
- fffff: Represents the five most significant digits of the second's fraction; that is, it represents the hundred-thousandths of a second in a date and time value.
- ffffff: Represents the six most significant digits of the second's fraction; that is, it represents the millionths of a second in a date and time value.
- fffffff: Represents the seven most significant digits of the second's fraction; that is, it represents the ten-millionths of a second in a date and time value.
Here is a complete C# code sample that uses these formats.
using System;
namespace DateTimeFormatInCSharpSample
{
class Program
{
static void Main(string[] args)
{
// Get current DateTime. It can be any DateTime object in your code.
DateTime aDate = DateTime.Now;
// Format Datetime in different formats and display them
Console.WriteLine(aDate.ToString("MM/dd/yyyy"));
Console.WriteLine(aDate.ToString("dddd, dd MMMM yyyy"));
Console.WriteLine(aDate.ToString("dddd, dd MMMM yyyy"));
Console.WriteLine(aDate.ToString("dddd, dd MMMM yyyy"));
Console.WriteLine(aDate.ToString("dddd, dd MMMM yyyy"));
Console.WriteLine(aDate.ToString("dddd, dd MMMM yyyy"));
Console.WriteLine(aDate.ToString("dddd, dd MMMM yyyy HH:mm:ss"));
Console.WriteLine(aDate.ToString("MM/dd/yyyy HH:mm"));
Console.WriteLine(aDate.ToString("MM/dd/yyyy hh:mm tt"));
Console.WriteLine(aDate.ToString("MM/dd/yyyy H:mm"));
Console.WriteLine(aDate.ToString("MM/dd/yyyy h:mm tt"));
Console.WriteLine(aDate.ToString("MM/dd/yyyy HH:mm:ss"));
Console.WriteLine(aDate.ToString("MMMM dd"));
Console.WriteLine(aDate.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss.fffffffK"));
Console.WriteLine(aDate.ToString("ddd, dd MMM yyy HH’:’mm’:’ss ‘GMT’"));
Console.WriteLine(aDate.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss"));
Console.WriteLine(aDate.ToString("HH:mm"));
Console.WriteLine(aDate.ToString("hh:mm tt"));
Console.WriteLine(aDate.ToString("H:mm"));
Console.WriteLine(aDate.ToString("h:mm tt"));
Console.WriteLine(aDate.ToString("HH:mm:ss"));
Console.WriteLine(aDate.ToString("yyyy MMMM"));
Console.ReadKey();
}
}
}
Above code sample generates the following output.

Here is a detailed tutorial on DateTime and formatting: Working with DateTime In C#
Learn about DateTime Class in C#
Calculate the Date Difference in C#
Eric DiamPosted Apr 25, 2024, 12:34 PM
DateTime is not a class but a structure, what a sh* article!
Joe PoolPosted Jul 6, 2023, 3:27 PM
Nice, but instead of using a hard-coded datetime value, how about an input box with an initial value of *DateTime.Now* that we can edit and see the output?
Farrukh azadPosted Jun 12, 2023, 7:40 PM
Good work dear friend
Harun OconnellPosted Jan 31, 2023, 8:19 PM
DateTime date; and date = DateOfBirth;
Harun OconnellPosted Jan 31, 2023, 5:23 PM
Hello, Try this code, it is written for date of birth: DateTime.TryParseExact(dateOfBirth, new[] {"yyyy-MM-dd", "yyyy/MM/dd", "MM/dd/yy", "dd-MMM-yy"}, null, DateTimeStyles.None, out date);
jay singhPosted Sep 14, 2022, 12:41 PM
GMT converted to G9T plz help
Faheem AhmadPosted Jul 8, 2022, 11:15 AM
Nice article, all in one place. Good job Suresh.
Sandip G PatilPosted Feb 4, 2022, 7:58 AM
Nice article...
Sameera MadushankaPosted Dec 16, 2021, 1:13 PM
Thank you, this helped me
Werayoot KunphaiPosted Mar 16, 2021, 4:27 AM
Thank yOU .......
Arun VRPosted Oct 29, 2020, 5:04 AM
Is there any way to gIs there any way to get date as January 1st, February 2nd, March 30th etc?et date as January 1st, February 2nd, March 30th etc?
mohammed almazariPosted Sep 28, 2020, 4:18 AM
Good article
Debipriya DasPosted Jun 12, 2020, 1:26 AM
Hi can anyone help me in converting fiscal year format YYYY-YYYY to YYYY/YYYY ???
Deepak KumarPosted Jun 2, 2020, 1:36 AM
DateTime.Now.ToString("yyyyMMddHHmmss");
Leslie TaylorPosted Mar 11, 2020, 9:51 AM
There are a few mistakes in the above table, formatted without time but results with time DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 05:50 DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 05:50 AM DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 5:50 DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 5:50 AM
Raju PaladiyaPosted Feb 21, 2020, 2:58 AM
Great Suresh. This is helped me. Thank you
shamma kaluboPosted Nov 28, 2019, 6:13 PM
Thanks Suresh, this was very helpful.
Jaime StuardoPosted Aug 20, 2019, 2:53 PM
If needed to display a preposition between the day and the month and between the month and the year (for example, for Spanish representation), a single quote can also be used: DateTime.Today.ToString("dddd, dd 'de' MMMM 'de' yyyy")
Arun ChristopherPosted Jun 11, 2019, 2:15 AM
I do not get this format mm/dd/yyy Ex: DateTime TodayDate = DateTime.Now; ,AspDateTo.Text = TodayDate.ToString("MM/dd/yyyy"); Answer :06-11-2019
Arun ChristopherPosted Jun 11, 2019, 2:13 AM
I do not get in this mm;dd/yyy ,
Joel FernandezPosted Jun 5, 2019, 11:23 PM
Thanks for sharing.
Safi UllahPosted May 18, 2019, 7:19 AM
Very very thanks.... my problem solve here.. searching problem occurse with date format and thanks solve with your help..
abel realPosted Apr 2, 2019, 4:46 AM
Useful thanks
ธีระเดช ศิลปเจริญPosted Feb 1, 2019, 8:21 AM
Very useful thanks
Peter ByrnePosted Oct 24, 2018, 10:12 AM
Useful reference thanks
Peter ByrnePosted Oct 24, 2018, 10:12 AM
You have some incorrect apostrophe's in these: DateTime.Now.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss.fffffffK") 2015-05-16T05:50:06.7199222-04:00DateTime.Now.ToString("ddd, dd MMM yyy HH’:’mm’:’ss ‘GMT’") Fri, 16 May 2015 05:50:06 GMT DateTime.Now.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss") 2015-05-16T05:50:06
Guest UserPosted Jul 31, 2018, 3:57 PM
"HH 24-hour clock hour, with a leading 0 (e.g. 29)" ...yea, because using a number less than 24 as an example would involve too much thought...as would providing an example of a PM case for HH format. Good job.
Anson DavisPosted Jun 26, 2018, 1:04 AM
Thanks it is very useful :-)
Amrinder SinghPosted Jun 4, 2018, 11:50 PM
Thanks it helped
Suresh KamrushiPosted Mar 23, 2018, 5:19 AM
Nice one!!! help to understand the format available.
Santhakumar MunuswamyPosted May 31, 2015, 11:37 PM
Thanks for sharing