0

I have two fields in my database for storing starttime and endtime. they are of datetime. I pick time from them using tostring("hh:mm tt"). Now I want to update only the time part of the date. I have dropdownlist to select hour and minutes and AM/PM. How can I update the time of date stored in sql server using Entity framework / LINQ in MVC3 application.

Please suggest

DotnetSparrow
  • 27,428
  • 62
  • 183
  • 316

3 Answers3

0

actually you don't really need to touch the linq part of this, basically what you want to do is just to convert the string back to a datetime object and just manipulate the datetime object by either creating a new datetime object or add/minus mm/dd/yy hours or minutes.

melaos
  • 8,386
  • 4
  • 56
  • 93
0

You must always update the whole datetime - it means you must build a new DateTime in your application and use correct Date part and defined Time part.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
0

create new DateTime Object

 DateTime mydate = New DateTime(2011, 6, 1, 12, 30, 0);

or

DateTime mydate = DateTime.Parse("2011-06-1 12:30:00 PM");
Amir Ismail
  • 3,865
  • 3
  • 20
  • 33