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
Hamza Shah
NA
87
23k
In date range Start date should be one month before the current date
Nov 16 2020 5:33 AM
In my attendance portal, I've set the date range "Start" to "End". In these two fields I've used date picker so the admin can search the attendances from Whatever date he selected to whatever date he wanted. But I want my start date value to be one month before the current date. I've searched it a lot but can't find better one.
Here's my View code
<div
class
=
"row"
>
<div
class
=
"form-group"
>
<div
class
=
"col-md-3"
>
@Html.DropDownList(
"Employee"
,
(IEnumerable<SelectListItem>)TempData[
"Employees"
],
"All Employee"
,
new
{ @
class
=
"form-control"
, onchange =
"this.form.submit();"
})
</div>
<div
class
=
"col-md-3"
>
<input id=
"start"
autocomplete=
"off"
name=
"start"
class
=
"form-control datepicker"
placeholder=
"Start"
value=
"@startDate"
/>
</div>
<div
class
=
"col-md-3"
>
<input id=
"end"
class
=
"form-control datepicker"
autocomplete=
"off"
name=
"end"
placeholder=
"End"
value=
"@endDate"
/>
</div>
<div
class
=
"col-md-3"
>
<input type=
"submit"
value=
"Search"
class
=
"btn btn-success"
/>
</div>
</div>
</div>
And here's my controller code
[HttpPost]
[ValidateAntiForgeryToken]
public
ActionResult All(
int
? Employee,
int
? page,
string
start,
string
end)
{
List<Attendance> attendanceList;
if
(Employee !=
null
)
{
if
(start !=
""
&& end !=
""
)
{
DateTime dtstart = Convert.ToDateTime(start);
DateTime dtend = Convert.ToDateTime(end);
attendanceList = db.Attendance.ToList().Where(x => x.Emp_Id == Employee && x.Date >= dtstart && dtend >= x.Date).ToList();
}
else
{
attendanceList = db.Attendance.ToList().Where(x => x.Emp_Id == Employee).ToList();
}
return
View(attendanceList);
}
Reply
Answers (
3
)
Edit with Model popup on row click.
dataTable and session variable.