Quantcast
Viewing latest article 16
Browse Latest Browse All 42

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

Getting the Date part of a DateTime object didn't workout for me because I'm working on the client-side and the returned web service values have some null dates. As a result, it tries to get the Date part of a null value and it throws a runtime exception. The following example is how I solved my problem:

string dt = employer.BirthDay.ToString();if(dt == ""){ dt = "N/A";}else dt = dt.Substring(0,10);
  1. Get the DateTime value as string into a string variable.
  2. Check if it's null. If null, assign a string variable.
  3. If not null, get the first 10 characters of the string DateTime value and assign it to the string variable.

I'm sharing this for future reference.


Viewing latest article 16
Browse Latest Browse All 42

Trending Articles