0

I have a datetime on my MSSQL table that I'm trying to get.

Originally, I had this:

reader.GetDateTime(ordinals.DateBirth);

It works fine, however It's taking the time as well. If I add "Date" at the end, It will put everything to 12:00:00 (midnight). and If I add ToShortDateString, nothing really happens, I can see the same result.

What I want to achieve basically is to get the Date only while keeping it a DateTime type.

Convert.ToDateTime(reader.GetDateTime(ordinals.DateEtabDrc).Date.ToShortDateString());
Hackawar
  • 25
  • 1
  • 6
  • `reader.GetDateTime(ordinals.DateBirth).ToShortDateString()`? – Ajay Gupta Jul 12 '18 at 09:28
  • I understand that it would work I want it back to DateTime type, that's impossible? It must be a string? – Hackawar Jul 12 '18 at 09:29
  • _"get the Date only while keeping it a DateTime type"_ - you can't, a DateTime inherently also contains a time. You should fix this at the display side, i.e. when converting it to a string. – CodeCaster Jul 12 '18 at 09:36
  • @CodeCaster I see so are there is downsides If I load the datetime from the database as a string? or it's just fine – Hackawar Jul 12 '18 at 09:42
  • It's not a string in the database. It should only become a string when you display it. – CodeCaster Jul 12 '18 at 09:42

0 Answers0