This is a migrated thread and some comments may be shown as answers.

[Solved] Date format changes when month is changed

3 Answers 58 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Adrian O'Connor
Top achievements
Rank 1
Adrian O'Connor asked on 04 May 2010, 10:10 AM
Hi there,

I'm using the Calendar control on a British system that has date format "dd/MM/yyyy".

I've got the following calendar:

<%= Html.Telerik().Calendar() 
            .Name("Calendar") 
            .HtmlAttributes(new { style = "width:100%;" }) 
            .Selection(settings => settings 
                        .Action("Index", "Courses", new { date = "{0}" }) 
                        .Dates(Course.GetCourseDates()) 
            ) 
            .Value(Request["date"] != null ? DateTime.Parse(Request["date"]) : DateTime.Now)  
%> 
 

If the user clicks a date in the default month (currently May), the url that is generated looks like this:

http://localhost/app/controller/action?date=20/05/2010

However, if I then click to change the month, to April, in this case and click a date (21st) the generated URL is this:

http://localhost/app/controller/action?date=4/21/2010

Which can't be parsed, because it's switched to MM/dd/yyyy.

Is this a known bug? Is there anything I can do to the calendar's configuration to work around the problem -- for example, if I could force it to use an ISO formatted date string, that would work.


3 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 04 May 2010, 11:46 AM
Hello Adrian O'Connor,

You can try to turn on the globalization of the component. Check this help topic for more information.

If the problem still persists you can set the shortDate format on the client. Use this code snippet to achieve that:
<% Html.Telerik().ScriptRegistrar()
                 .OnDocumentReady(() =>
                 { %>
                     jQuery.telerik.cultureInfo.shortDate = 'dd/MM/yyyy';
                 <% });
%>
With this code you will set your own shortDate format, which will be used to format the selected date.

Greetings,
Georgi Krustev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Adrian O'Connor
Top achievements
Rank 1
answered on 04 May 2010, 04:38 PM
Setting jQuery.telerik.cultureInfo.shortDate did the trick. Thanks very much for your assistance.

Adrian
0
Carlos
Top achievements
Rank 1
answered on 23 Feb 2012, 05:28 PM
how do you set this in razor??

currently my code look like

@(
     Html.Telerik().ScriptRegistrar()
                     .DefaultGroup(group => group
                                            .Compress(true)
                                  )
                                  .Globalization(true)
                                  
    )
Tags
Calendar
Asked by
Adrian O'Connor
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Adrian O'Connor
Top achievements
Rank 1
Carlos
Top achievements
Rank 1
Share this question
or