How to pick Feb 29 in DateTimePicker without specifying the year

2 posts, 0 answers
  1. SPE
    SPE avatar
    34 posts
    Member since:
    Sep 2010

    Posted 27 Feb 2013 Link to this post

    Hi,

    I made a customized version of DateTimePikcker in a way that it displays month and day only (MM-dd),  as I needed to display the month and day parts as a separate field from the year component.

    So far it's worked all fine - for input dates with yy-MM-dd or MM-dd formats.

    The problem is that it's impossible to display the date '02-29' without specifying the year.

    That is, unless I type in the date using the yy-MM-dd (where yy is the leap year), DateTimePicker does not support Feb 29 so I have to type something like 2014-02-29.

    Is there any way to type and display 02-29 without the user actually having to specify the year?

    Thank you in advance for your kind reply.

        <UserControl.Resources>
            </Style>
            <Style x:Key="CalendarStyle" TargetType="telerik:RadCalendar">
                <Setter Property="MonthViewHeaderFormat" Value="MMMM" />
            </Style>

                                <telerik:RadDateTimePicker Grid.Column="1" Grid.Row="8"
                                                           x:Name="birthDate"
                                                           InputMode="DatePicker"
                                                           CalendarStyle="{StaticResource CalendarStyle}" 
                                                           TextAlignment="Right"
                                                           Height="16"
                                                           Margin="2,0"
                                                           DateTimeWatermarkContent="Enter a Date"
                                                           SelectedDate="{Binding CurrentIndividual.BirthDateTime, Mode=TwoWay}"/>
  2. Boyan
    Admin
    Boyan avatar
    758 posts

    Posted 01 Mar 2013 Link to this post

    Hi Sunmig,

    I don't think that this will be possible. The thing is that even that you have hidden the year, in the background the entry is parsed to a DateTime. When you write 02-29 this is parsed as 02-29-2013 and as this year there is no 29 th of February the parsing fails.So the SelectedValue is of type DateTIme, so there is always an year part and if you don't specify the year it automatically takes the current year.

    The only thing that you can do is to use custom parsing as shown in this help article, but you will still have to specify an year, but you can specify one that have 02-29.

    Hope this helps.

    All the best,
    Boyan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
Back to Top