Reputation: 193
I want to convert date entered int String to DateTime type
I use the following
DateTime date = Convert.ToDateTime(dateText);
Let say the dateText=5/20/2014 DateTime date become 5/20/2014 and 12:00:00 AM. I I want the current time of the day to be picked up instead of 12:00:00 AM.
Is there a workaround?
Upvotes: 1
Views: 65
Reputation: 11035
After you do:
DateTime date = Convert.ToDateTime(dateText);
Then do:
DateTime fullDate = new DateTime(date.Year, date.Month, date.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
...or as suggested by Ulugbek Umirov:
DateTime fullDate = date.Add(DateTime.Now.TimeOfDay);
Upvotes: 5
Reputation: 5943
Try this :
DateTime date = Convert.ToDateTime(dateText + " " + DateTime.Now.TimeOfDay);
Upvotes: 1