TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Marius Vasile
594
1.9k
145.7k
asp.net core filter by two dates
Mar 14 2021 3:49 PM
I am trying to filter results of a query using a StarDate and EndDate. My data is saved in format dd/mm/yyyy hh:mm:ss AM/PM and I want to use only date as parameter for filtering. If I use full date format (
3/12/2021 12:41:04 PM
) is working very well but I want to be able to use only date. What I have is:
public
IList<WOMain> WOMainL { get; set; }
public
void
OnGet()
{
WOMainL = _context.WOMains.ToList();
}
public
void
OnPost(DateTime sdate, DateTime edate)
{
WOMainL = _context.WOMains.Where(s => s.CreateDate <= sdate && s.CreateDate >= edate).ToList();
}
<form method=
"post"
>
Start Date: <input type=
"datetime"
name=
"sdate"
/>
End Date: <input type=
"datetime"
name=
"edate"
/>
<input type=
"submit"
value=
"Submit"
class
=
"btn"
/>
</form>
<div
class
=
"row no-gutters mt-2"
>
<div
class
=
"col-md-1 text-center"
style=
"background-color:firebrick;"
>
<label
class
=
"text-white pl-2"
>WO NUmber</label>
</div>
<div
class
=
"col-md-2 text-center ml-1"
style=
"background-color:firebrick;"
>
<label
class
=
"text-white pl-2"
>Create Date</label>
</div>
<div
class
=
"col-md-2 text-center ml-1"
style=
"background-color:firebrick;"
>
<label
class
=
"text-white pl-2"
>OrgID</label>
</div>
<div
class
=
"col-md-3 text-center ml-1"
style=
"background-color:firebrick;"
>
<label
class
=
"text-white pl-2"
>User ID</label>
</div>
<div
class
=
"col-md-2 text-center ml-1"
style=
"background-color:firebrick;"
>
<label
class
=
"text-white pl-2"
>WOStatus</label>
</div>
</div>
@foreach (var item in Model.WOMainL.OrderByDescending(s => s.WONumber))
{
<div
class
=
"row no-gutters mt-2"
>
<div
class
=
"col-md-1"
>
<span
class
=
"form-control text-center"
>@Html.DisplayFor(modelItem => item.WONumber)</span>
</div>
<div
class
=
"col-md-2 ml-1"
>
<span
class
=
"form-control text-center"
>@Html.DisplayFor(modelItem => item.CreateDate)</span>
</div>
<div
class
=
"col-md-2 ml-1"
>
<textarea rows=
"1"
class
=
"form-control text-center"
>@Html.DisplayFor(modelItem => item.OrgID)</textarea>
</div>
<div
class
=
"col-md-3 ml-1"
>
<textarea rows=
"1"
class
=
"form-control text-center"
>@Html.DisplayFor(modelItem => item.UserID)</textarea>
</div>
<div
class
=
"col-md-2 ml-1"
>
<span
class
=
"form-control text-center"
>@Html.DisplayFor(modelItem => item.WOStatus)</span>
</div>
</div>
}
Reply
Answers (
2
)
How to increase cell quantity using keyboard up and down arrows ?
how to upload image to sql database