Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

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 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>


What I have tried:

I have tried using different date formats but it didn't work.
Posted
Updated 10-Apr-19 0:38am

1 solution

Have you checked the date format ?

It should be same as local.

Either you can set your server date format as your local or you may convert date format according server date format before deployment.
 
Share this answer
 
Comments
Member 11445100 10-Apr-19 7:41am    
Do i have to write the conversion code in the controller or somewhere else?
Nirav Prabtani 10-Apr-19 8:36am    
tm.FromDate = DateTime.ParseExact(fmdate, "dd-MM-yyyy", CultureInfo.InvariantCulture);
tm.EndDate = DateTime.ParseExact(todate, "dd-MM-yyyy", CultureInfo.InvariantCulture);

You can use MM-DD-YYYY vice versa, according to your need
Member 11445100 10-Apr-19 8:43am    
Thanks i will try this and let you know

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900