开发者

compare date today

开发者 https://www.devze.com 2023-04-04 17:07 出处:网络
I am new to MVC.I want to use the dropdownlist to show onchange, once the dropdownlist changes anything, the view page wi开发者_开发技巧ll show the data from database

I am new to MVC. I want to use the dropdownlist to show onchange, once the dropdownlist changes anything, the view page wi开发者_开发技巧ll show the data from database

@Html.DropDownList("id", new SelectList(
    new[] { "Today", "Yesterday", "Older" }), " [Show By] ", 
    new { id = "history", onchange = "this.form.submit();" 
})

public ActionResult History(int id)
{

}

How do I type this statement? I am using lightspeed > LINQ. My database entity name is "visitors" and my field name is "timeout". My database store inside is datetime default which is formatted as following "5/9/2011 4:48:03 PM"


You need use DateTime Compare or CompareTo methods in your Linq Expression. For example, if timeout field is DateTime(not nullable type) you can write:

dbContext.visitors.Where(v=>v.timeout.CompareTo(DateTime.Now)==0); //today
dbContext.visitors.Where(v=>v.timeout.CompareTo(DateTime.Now.AddDays(-1))==0); //yesterday
dbContext.visitors.Where(v=>v.timeout.Compare(DateTime.Now.AddDays(-1))<0); //older
0

精彩评论

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

关注公众号