Get Today’s Date

Get today's date
When dealing with dates most of the time we need to get current date or today’s date in C# code to perform some operations. DateTime class provides DateTime.Today property to get today’s date. Today property returns current date only and does not include time in it so we can use Today property in code where we just need today’s date and not time. Then we can use .ToString() to format string date as per our need.

Sample code to get today’s or current date [C#]

using System;
using System.Globalization;
public class DateTimeAddYear
public static void Main()
// Get current date.
DateTime todaysDate = = DateTime.Today;
//And show today's date in needed format
Console.WriteLine(todaysDate.ToString("dd MMM yyyy"));
//12 Jan 2012


Post a Comment