Get just the Date part - CSharp Language Basics

CSharp examples for Language Basics:Date Time

Description

Get just the Date part

Demo Code

using System;//from   w w w . ja v  a  2 s.c om
class Program
{
    static void Main(string[] args)
    {
        // Get just the date part ...
        DateTime date = DateTime.Today;
        DateTime date1 = date.Date;
        // Either version gives "7/15/07 12:00:00 AM" <--- (midnight this morning)
        Console.WriteLine("Today is {0}", date);
        TimeSpan time = date.TimeOfDay;
        Console.WriteLine("The time of day is {0}", time); // e.g. "2:43:29.4672181"  <--- (time plus fraction)
    }
}

Result


Related Tutorials