We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Date problems

I have some strange things with displaying dates in DatePicker control.

This is my record in the database:



and when I load this in the view, I get



and this is ok. But, when I change the date to 29.3.1982., the value in the database is changed



In the controller, Edit method, the value is ok.



but after that, the view displays



I'm using locale property for the control



but event without that, it's the same.

And one more thing...if I set the date to 29.3.1983., and every date after that, I't ok.







In addition to the year 1982., I get wrong dates from 29.3.1982. to 31.10.1982. The date 1.11.1982. is ok.
This sounds like winter/summer time, but why only for the year 1982. and earlier??

Thanks.
Bernard.

8 Replies

DL Deepa Loganathan Syncfusion Team November 19, 2018 11:27 AM UTC

Hi Bernard,  
 
Sorry for the inconvenience.  
 
We have investigated the code snippets provided in your last update. Based, on the provided information, we suspect that issue might be due to the time zone discrepancies between the client machine and the server machine time zone. we would like to let you know that by default, the Date values will be converted to its equivalent UTC date and time object upon post action. In Croatian timezone (i.e. UTC+1) the posted date time will be posted with addition of a hour and that is the reason you get the value one day behind the posted value. 
 
However, in your application, you could overcome this behavior by setting the TimeZone API of DatePicker to false as shown in the below code.  
 
[index.cshtml] 
 
@using (Html.BeginForm()) 
{ 
    @Html.ValidationSummary(true) 
 
    @Html.EJ().DatePickerFor(model => model.Value).Width("50%").Locale("hr-HR").TimeZone(false) 
    @Html.ValidationMessageFor(model => model.Value) 
 
    @Html.EJ().Button("btn").Size(ButtonSize.Small).Text("Post").Type(ButtonType.Submit) 
} 
 

If the solution provided does not resolve your problem, kindly get back to us with the view page, Master page and controller page of your application, so that we can investigate further to check the exact cause of the issue.  

Regards, 
Deepa L. 



BJ Bernard Jurlina November 19, 2018 09:10 PM UTC

Hi Deepa,

and thank you for your answer. Unfortunately, TimeZone doesn't solve my problems. Still, if I select date between 29.3.1982. and 31.10.1982., I get one day less when open my edit page, but the value in the database is saved ok. 

The server and the client are on the same machine, my local computer, so maybe the TimeZone property doesn't matter in this situation.
But still, why is this only for the year 1982 and earlier? If I set the date to 10.5.2016., everything is fine.

I'm sending my controller, layout and view page in the attachment. My syncfusion version if 16.3.0.21.

Thank you in advance.
Regards,
Bernard.

Attachment: CreateEdit_7a9ade22.rar


BJ Bernard Jurlina November 19, 2018 09:26 PM UTC

I'm testing this with datetime picker, istead of datepicker, and this is what I found out.

This is the control in the view:


And if I set the date like this (field DatumRodjenja if date type on sql server database):
update Stranka set DatumRodjenja = '5/10/2018' where StrankaID = 2
then my view is showing


But if I set the date
update Stranka set DatumRodjenja = '5/10/1970' where StrankaID = 2
the view shows


So, if I set the datetimepicker with TimeZone(false)

the view shows


My timezone is


Thanks.
Bernard.


DL Deepa Loganathan Syncfusion Team November 20, 2018 05:30 PM UTC

Hi Bernard, 
 
We regret the inconvenience caused. 
 
Based on the provided information, we have analyzed further about your query on EJ DateTimePicker. and found that the reported issue is occurring in DateTimePicker, due to the DST (Daylight Savings Time) effected with Time Zone observed in your location (Croatia). Due to this discrepancies in time, the date which received from the database, changes with different dates based on the DST conversions.  
 
We have prepared an solution  to resolve this issue by checking whether the given selected date fall under DST(day light saving) or not.  Kindly, check out the below code sample which depicts the solution to resolve the issue at your end. 
 
[index.cshtml] 
@using (Html.BeginForm()) 
{ 
    @Html.ValidationSummary(true) 
 
    @Html.EJ().DateTimePickerFor(model => model.objectValue).Width("50%").Locale("hr-HR").ClientSideEvents(e => e.Create("onCreate")) 
    @Html.ValidationMessageFor(model => model.objectValue) 
 
    @Html.EJ().Button("btn").Size(ButtonSize.Small).Text("Post").Type(ButtonType.Submit) 
} 
 
<script> 
    function onCreate(args) { 
        var jan = new Date(new Date(this._options.value).getFullYear(), 0, 1); 
        var jul = new Date(new Date(this._options.value).getFullYear(), 6, 1); 
        //checking the difference between timezone offset of current timezone with the DST time. 
        if (new Date(this._options.value).getTimezoneOffset() - Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset()) == 0) { 
            // if the timezone offset is -60, then 1 hour will added to the date value 
            updatedValue = new Date(this._options.value).setHours(new Date(this._options.value).getHours() + 1); 
            this.option("value", new Date(updatedValue)); 
        } 
    } 
</script> 
 
 
We have also, attached a sample application with the above code sample in the below link. 
 
 
Also, check out the below link which has information about the solution provided. 
 
 
Please, let us know if you need any further assistance. 
 
Regards, 
Deepa L. 



BJ Bernard Jurlina November 20, 2018 06:47 PM UTC

Hi Deepa L.,

and thank you for your answer. Unfortunately, this solution is working with the dates from 3/31/1982 and earlier. If I set the date, for example, on 5/10/2018, I get the result like 5/9/2018. I tried to use something like this:

function onCreate(args) {
var mod = '@Model.DatumRodjenja';
        if (mod != "") {
            this.option("value", stringToDate(mod, "dd.mm.yyyy.", "."));
        }
}

where I replace value in the datepicker with the value from the Model, and it's working fine.

But, this is the same thing in the grid, where the date in the database is 5/10/1970, but in the grid (this is the grid)

@(Html.EJ().Grid<object>("gridS")
        .Datasource((IEnumerable<object>)ViewBag.dsStranka)
        .AllowPaging()
        .ToolbarSettings(toolbar =>
        {
            toolbar.ShowToolbar().ToolbarItems(items =>
            {
                items.AddTool(ToolBarItems.Search);
            });

        })
        .EnableRowHover(false)
        .AllowSelection(false)
        .IsResponsive(true)
        .AllowSorting(true)
        .EnableTouch(true)
        .FilterSettings(filter => { filter.FilterType(FilterType.Excel); })
        .Locale("hr-HR")
        .Columns(col =>
        {
            col.Field("StrankaID").HeaderText("StrankaID").IsPrimaryKey(true).Visible(false).Add();
            col.Field("Prezime").HeaderText("Prezime").Width(110).Format("<a rel='nofollow' href=" + @Url.Action("CreateEdit", "Strankas") + "/{StrankaID}>{Prezime}</a>").Add();
            col.Field("Ime").HeaderText("Ime").Width(110).Add();
            col.Field("OIB").HeaderText("OIB").Width(110).Add();
            col.Field("DatumRodjenja").HeaderText("Datum rođenja").Format("{0:dd.MM.yyyy.}").Width(110).Add();
            col.Field("MjestoNaziv").HeaderText("Mjesto").Width(110).Add();
            col.Field("Mobitel").HeaderText("Mobitel").Width(110).Add();
            col.Field("Email").HeaderText("E-mail").Width(110).Add();
        })
)

I get this



And, when I try to display the value from the grid in alert box, from querycellinfo event, the this red value I get



and for the second row in the grid, I get



It's little weird, the year 2018 is +0200, but the year 1970 is +0100 and one hour less. :(

B.


SI Silambarasan I Syncfusion Team November 22, 2018 04:12 AM UTC

Hi Bernard, 

Sorry for the inconvenience, 

We have analyzed about the reported issue in EJ DateTimePicker. While analyzing about the issue related to time zone affected with DST in your location (Croatia), we found that DST is not observed in Croatia in the years before 1983. So, one hour is difference is updated with the dates from years before 1983. So, to overcome this issue we recommend you to make use of the below code snippet in your application to resolve the issue. 

[index.cshtml] 
@model ej1mvc.Controllers.DateTimePickerModel 
 
@using (Html.BeginForm()) 
{ 
    @Html.ValidationSummary(true) 
 
    @Html.EJ().DateTimePickerFor(model => model.Value).Width("50%").Locale("hr-HR").ClientSideEvents(e => e.Create("onCreate")) 
    @Html.ValidationMessageFor(model => model.Value) 
 
    @Html.EJ().Button("btn").Size(ButtonSize.Small).Text("Post").Type(ButtonType.Submit) 
} 
 
<script> 
    function onCreate(e) { 
        if (new Date(e.model.value).getFullYear() < 1983) { 
            this.model.value = new Date(new Date(e.model.value).getTime() - (new Date(e.model.value).getTimezoneOffset() * 60 * 1000)); 
            this._updateDateTime(); 
        } 
    } 
</script> 

We have also attached an application which is globalized with culture ‘hr-HR’ and EJ DatePicker also globalized to culture ‘hr-HR’ with above code to demonstrate the solution. 


[Global.asax.cs] 
protected void Application_BeginRequest(Object sender, EventArgs e) 
        { 
            CultureInfo.CurrentCulture = new CultureInfo("hr-HR"); 
            CultureInfo newCulture = (CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); 
            newCulture.DateTimeFormat.ShortDatePattern = "dd.MM.yyyy."; 
            newCulture.DateTimeFormat.DateSeparator = "."; 
            System.Threading.Thread.CurrentThread.CurrentCulture = newCulture; 
        } 

Reference for DST observed in Croatia: 
DST affected Years: https://www.timeanddate.com/time/change/croatia/zagreb (kindly check years before 1983). 

If the problem still persists at your end. kindly let us know your availability so that we can schedule a web meeting to check for this issue and provide a prompt solution to overcome this issue. 

Regards, 
Silambarasan 



BJ Bernard Jurlina November 22, 2018 12:43 PM UTC

Excellent,

I knew it was something like "greater force" in this. :)
Ok, I will use your advice to overcome this issue for the datetimepicker control. Just, how to solve this in Grid?
When I use the same data in the grid, the date is wrong. Maybe some event on load grid to catch date column and change it's data?

Thanks!
Regards,
Bernard.


PO Prince Oliver Syncfusion Team November 23, 2018 12:17 PM UTC

Hi Bernard, 

Thank you for your update. 

You can use load event of ejGrid to modify the dataSource before binding it to Grid. But we need to find the cause of the issue. So kindly share the following details.  
  
1.           Are you facing the reported issue when client and server time zone are different? 
2.           If yes, share your client and server time zones. 
3.           Share the full grid rendering code (cshtml and C#) 
4.           Are you facing the reported issue in chrome browser alone.? Share your browser details like version and browser name. 
5.           Kindly share the details regarding your dataSource. 
6.           Kindly share the Grid model. Refer the below screenshot to share the model in string type 

 

Requested details will help us to reproduce the reported issue at our end. 

Regards, 
Prince 


Loader.
Live Chat Icon For mobile
Up arrow icon