开发者

updating time of datetime field using linq

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 mi开发者_运维知识库nutes and AM/PM. How can I update the time of date stored in sql server using Entity framework / LINQ in MVC3 application.

Please suggest


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.


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.


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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜