Languages
[Edit]
EN

C# / .NET - convert DateTime to date only

13 points
Created by:
Dharman
518

In C# / .NET it is possible to get date part of DateTime object in the following way.

1. DateTime.Date property example

DateTime now = DateTime.Now.Date; // date only

Console.WriteLine(now.ToString());

Output:

08/14/2019 00:00:00
Notes: 
  • this example has been run with independent culture.
  • time part is set to zeros after Date property has been used.

References

  1. DateTime Structure Method - Microsoft Docs
  2. DateTime.Date Property - Microsoft Docs
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

C# - DateTime conversion

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join