Quantcast
Channel: How to remove time portion of date in C# in DateTime object only? - Stack Overflow
Viewing all articles
Browse latest Browse all 42

Answer by Nathanael Mayne for How to remove time portion of date in C# in DateTime object only?

$
0
0

Use date.ToShortDateString() to get the date without the time component

var date = DateTime.Nowvar shortDate = date.ToShortDateString() //will give you 16/01/2019

use date.ToString() to customize the format of the date

var date = DateTime.Nowvar shortDate = date.ToString('dd-MMM-yyyy') //will give you 16-Jan-2019

Viewing all articles
Browse latest Browse all 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>