TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C# DateTime.Today

This C# example uses the DateTime.Today property to get the current day.

DateTime.Today returns just the day—without the time.

This is different from DateTime.Now, which returns as much information as it can. The Today property returns a DateTime struct with the hour, minutes and seconds set to zero.

DateTime.Now: Current Time

Example. This program gets the current day (with Today) and the current time (with Now). The program was executed in the early afternoon, but Today is still set to midnight. Today is the same as the Now property. But it has no time.

Tip: This program was run on a specific date. When you run it on your computer, the time will differ.

C# program that uses DateTime.Today

using System;

class Program
{
    static void Main()
    {
	DateTime today = DateTime.Today;
	DateTime now = DateTime.Now;

	Console.WriteLine(today);
	Console.WriteLine(now);
    }
}

Output

2/25/2014 12:00:00 AM
2/25/2014 1:29:21 PM

Usage. Today is useful if you need to use a range of DateTimes starting on the current day. You could determine whether a piece of data was updated today or not by testing it against DateTime.Today.

DateTime Examples

Summary. We used the DateTime.Today property, which has an important difference from DateTime.Now. It contains no values other than the current day. This makes it useful for sorting and filtering tasks, or when you simply don't need the time.

Note: You can get DateTime.Today from DateTime.Now on your own as well. Simply remove the hours, minutes and seconds.


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf