Problem Date value. Day transforms it into a Month

Hello!
I have a problem with the datepicker.
When you select date, the date format is changed and the day transforms it into a month.

@ViewBag.culture = "es"

<ejs-datepicker locale="@ViewBag.culture" format="dd/MM/yyyy" id="datepicker" firstDayOfWeek="1" placeholder="Día" name="datepicker" showTodayButton="true"></ejs-datepicker>




Attachment: Screenshot_3_384b1c1f.rar

4 Replies

BC Berly Christopher Syncfusion Team May 7, 2020 10:04 AM UTC

Hi Santiago, 
  
Greetings from Syncfusion support.  
  
We have checked the reported scenario based on the provided code example and screenshot. Unfortunately the reported issue is not occurred at our end and while select the value as “May 4, 2020” then we can receive same date value in the backend.  
  
Also, we suspect that issue may be caused due to value got in the back end in the default culture date format (like in en-US, date format will be MM/dd/yyyy). So, this conflicts may be occurred in the date value received in the back end.  
  
For your convenience, we have prepared the sample and attached it below. 
  
Screenshot: 
  
 
  
[index.cshtml] 
 
<ejs-datepicker id="datepicker" width="250px" locale="@ViewBag.culture" format="dd/MM/yyyy" change="OnChange" firstDayOfWeek="1" placeholder="Día" name="datepicker" showTodayButton="true"></ejs-datepicker> 
<script> 
    document.addEventListener('DOMContentLoaded', function () { 
        datepicker = document.getElementById('datepicker').ej2_instances[0]; 
        var L10n = ej.base.L10n; 
        L10n.load({ 
            'es': { 
                'datepicker': { 
                    placeholder: 'marcador de posición', 
                    today: 'hoy' 
                } 
            } 
        }); 
        loadCultureFiles('es'); 
       // ej.base.setCulture('es'); //Set culture file globally 
 
    }); 
    function loadCultureFiles(name) { 
        var files = ['ca-gregorian.json', 'numbers.json', 'timeZoneNames.json']; 
        if (name === 'ar') { 
            files.push('numberingSystems.json'); 
        } 
        var loader = ej.base.loadCldr; 
        var loadCulture = function (prop) { 
            var val, ajax; 
            if (name === 'ar' && prop === files.length - 1) { 
                ajax = new ej.base.Ajax(location.origin + location.pathname + '/../../cldr-data/supplemental/' + files[prop], 'GET', false); 
            } else { 
                ajax = new ej.base.Ajax(location.origin + location.pathname + '/../../cldr-data/main/' + name + '/' + files[prop], 'GET', false); 
            } 
            ajax.onSuccess = function (value) { 
                val = value; 
            }; 
            ajax.send(); 
            loader(JSON.parse(val)); 
        }; 
        for (var prop = 0; prop < files.length; prop++) { 
            loadCulture(prop); 
        } 
    } 
    function OnChange(args) { 
        $.ajax({ 
            url: "https://localhost:44334/Home/GetData", 
            type: 'GET', 
            data: { 
                dateTime: args.value.toISOString() 
            }, 
            contentType: 'application/json; charset=utf-8', 
           // dataType: "json", 
            success: function results(result) { 
                alert("done"); 
            }, 
            error: function (a, b, c) { 
                alert("Error!") 
            } 
        });   
    } 
</script> 
[HomeController.cs] 
public IActionResult Index() 
        { 
            ViewBag.culture = "es"; 
             return View(); 
        } 
        [HttpGet] 
        public ActionResult GetData(DateTime? dateTime) 
        { 
            return View(); 
        } 
 
  
So, please check the above sample and share the below details that will help us to check and proceed further at our end. 
  
·       Try to reproduce the issue in the above attached sample / Issue reproducing sample 
·       Syncfusion product version 
·       Have you used DatePicker component inside the scheduler? 
·       Replication procedure 
·       How did you get the value in the backend? 
  
Regards, 
Berly B.C 



SA Santiago May 8, 2020 08:33 PM UTC

Thank you so much for the quick anwser.

I have the datepiker in other views and have proven that it works perfectly with various cultures and formats. I only have a view of which happens what I have consulted before. I copy and paste all the code and the problem continues.

But as you think, it will be some detail that escapes me from the back-end.

Thank you very much for your time


SA Santiago May 8, 2020 09:51 PM UTC

Solved the problem by receiving the data that the daterpiker sends with a string instead of a DateTime and then converting the string to the user's culture



VIEW:
 @ViewBag.cultureDate" placeholder="Día" name="Date" showTodayButton="true">

BACK-END:

 public async Task Schedule(string Date)
     {
     var culture = CultureInfo.CurrentCulture;
       DateTime dateTimeValue;
        var shortDateFormat = culture.DateTimeFormat.ShortDatePattern.ToString();
         ViewBag.cultureDate = shortDateFormat; 

  if (String.IsNullOrEmpty(Date))
            {
                var d1 = DateTime.Now;
                date = d1;
                var d2 = d1.Date.ToString(shortDateFormat);
            }
            else
            {
                dateTimeValue = Convert.ToDateTime(Date, culture);
                date = dateTimeValue;
                var d2 = date.Date.ToString(shortDateFormat);
            }


     }







BC Berly Christopher Syncfusion Team May 11, 2020 06:21 AM UTC

Hi Santiago, 
  
We are glad to know that your issue is resolved. Please let us know if you need further assistance on this. 
  
Regards, 
Berly B.C 


Loader.
Up arrow icon