Guga Todua
Guga Todua

Reputation: 522

Remove time from Datetime input

I have this field in User table

        public DateTime BirthDate { get; set; }

When I am registering new user from UI, I have to input BirthDate too. But I can not remove time from DateTime. datetimeproblem I am obligated to input specific time next to date. How Can I remove it?

Upvotes: 0

Views: 372

Answers (1)

Use DateTime.Parse or DateTime.ParseExtract or DateTime.TryParse.

Sample:

myEntity.BirthDate = DateTime.Parse(viewModel.BirthDate);

Ideal usage would be to get string from your UI first, and then convert it using aforementioned methods. This will allow you to safely catch exceptions and handle it properly, regardless of what UI framework you're using.

Upvotes: 1

Related Questions