-3

Hello I know this is a duplicate question however I want to remove the Time in DateTime format.

For example I have this DateTime value 8/3/2016 12:00:00 AM. I want to remove the Time 12:00:00 AM and use the remaining value.

I tried this one

DateTime DATE= Convert.ToDateTime(DATE);

var date2 = DATE.date; but it only take the date not the whole value.

Traf De Law
  • 83
  • 1
  • 1
  • 8
  • The duplicate question will have your answer. – David Tansey Aug 03 '16 at 02:14
  • If you know this is a duplicate question, then why are you posting it again instead of using the answer to one of the others? – Ken White Aug 03 '16 at 02:18
  • @DavidTansey The other answer that I saw is they just get the date only – Traf De Law Aug 03 '16 at 02:20
  • 1
    Possible duplicate of [How to remove time portion of date in C# in DateTime object only?](http://stackoverflow.com/questions/6121271/how-to-remove-time-portion-of-date-in-c-sharp-in-datetime-object-only) – nhouser9 Aug 03 '16 at 02:21
  • @nhouser9 using the `.Date` it will get the whole value of 8/3/2016? Not the date only? – Traf De Law Aug 03 '16 at 02:26
  • @nhouser9 if not then it is different to what I want. – Traf De Law Aug 03 '16 at 02:34
  • You're asking how to get the date only, and the linked duplicate shows you how to get the date only. If that's not what you want, [edit] your question to explain what it is you **really** want instead of repeating the same nonsense over and over again in comments. – Ken White Aug 03 '16 at 02:43
  • @KenWhite in my example I want to get the whole 8/3/2016 and remove the 12:00:00 AM in datetime. – Traf De Law Aug 03 '16 at 02:46
  • As I said, [edit] your question to make it clear what you're asking. **Don't say it again in comments, but [edit] your question and say it there instead.** – Ken White Aug 03 '16 at 02:48
  • @KenWhite no need to **argue** I solve my own problem now. – Traf De Law Aug 03 '16 at 02:52
  • I'm not arguing. I'm trying to get you to listen, but you're still not doing so. – Ken White Aug 03 '16 at 02:54

2 Answers2

-1

Try this:

string date = DateTime.Now.ToShortDateString();

Bruno Soares
  • 232
  • 2
  • 6
-1

What you ask is not doable in the terms you seek. If you want operations only on the Date parts you should first extract Date parts like this:

var dateString = "8/3/2016 12:00:00 AM";
DateTime date = DateTime.Parse(dateString);

You can work only with the date part using Day, Month, Year properties and if needed DayOfYear, DayOfWeek properties. If you want to print Date only use:

1. Console.WriteLine(date.ToShortDateString()) or
2. Console.WriteLine(date.ToLongDateString()) or
3. Console.WriteLine(date.ToString("d")) // same as ToShortDateString() // or
4. Console.WriteLine(date.ToString("D")) // same as ToLongDateString() // or
5. Console.WriteLine(date.ToString("yyyy/MM/dd")) or
6. Console.WriteLine(date.ToString("//Other custom formats")
αNerd
  • 488
  • 1
  • 6
  • 11