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 Na'il for How to remove time portion of date in C# in DateTime object only?

$
0
0

If you want to remove part of time from a DateTime, try using this code:

DateTime dt = new DateTime();dt = DateTime.Now; //ex: 31/1/2017 6:30:20 PMTimeSpan remainingTime = new TimeSpan(0, dt.Hour - 5, dt.Minute - 29, dt.Second - 19);dt=dt.Add(remainingTime);label1.Text = dt.ToString("HH:mm:ss"); // must be HH not hh

the output : 01:01:01


Viewing all articles
Browse latest Browse all 42

Trending Articles



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