Question

Locked

Date range picker field shows invalid date

By aniket96 ·
Tags: Software
I am working on a project developed in .NET MVC where I am facing an issue regarding a daterangepicker functionality. The same functionality works on localhost but not on server where my application is hosted. I am using bootstrap’s daterangepicker class. The date format is same in the controller and the JavaScript. I’ll attach the code of the controller and the JavaScript.

Actual working :
A daterange is selected from the daterangepicker and the remaining fields are filled. After this step, I click on Save button and the details are saved. Once it is saved I can submit it and it gets submitted successfully.

Problem:
After saving the first time, when I navigate to the same page for modification, the daterangepicker shows invalid date. This works on localhost but not on the production server.

I have communicated with the hosting support team regarding this issue but there is nothing wrong from their end. Please let me know if anyone has faced this issue before.

Controller Code:
if (count == 1)
{
daterange = r.DateRange.Split('/');
fmdate = daterange[0].Trim();
todate = daterange[1].Trim();
tm.UserId = obj.UserId;
//DateTime fordate = DateTime.ParseExact("05/03/2018", "dd/MM/yyyy", CultureInfo.InvariantCulture);
tm.FromDate = DateTime.ParseExact(fmdate, "dd-MM-yyyy", CultureInfo.InvariantCulture);
tm.EndDate = DateTime.ParseExact(todate, "dd-MM-yyyy", CultureInfo.InvariantCulture);
tm.IsSubmited = false;
tm.IsApproved = false;
entity.TimesheetMasters.Add(tm);
entity.SaveChanges();

JavaScript Code:
<script>
$('#daterange').daterangepicker({

"dateLimit": {
"days": 5
},
"locale": {

"format": "DD-MM-YYYY",
"separator": " / ",
"applyLabel": "Apply",
"cancelLabel": "Cancel",
"fromLabel": "From",
"toLabel": "To",
"customRangeLabel": "Custom",
"weekLabel": "W",

"firstDay": 1
},
"weekStart": 5,
"showWeekNumbers": true,


});
</script>

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Share your knowledge

Related Discussions

Related Forums