The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range?

3 posts, 1 answers
  1. islam
    islam avatar
    4 posts
    Member since:
    Nov 2010

    Posted 12 Sep 2011 Link to this post

    hi all,
    i have an application which i use a RadDatePicker inside and the selected date binds a database field,
    now when i set the selected date to a very old one or  far in the future and then when i try to save the data to the domain service the server throws an exception "The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range".

    my code looks like this:
    <Telerik:RadDatePicker Grid.Row="1" Grid.Column="1" Height="22" SelectedDate="{Binding ToDate,Mode=TwoWay,NotifyOnValidationError=True, ValidatesOnDataErrors=True, ValidatesOnNotifyDataErrors=True,ValidatesOnExceptions=True}" IsEnabled="{Binding IsDatePickerEnabled}"/>  

    am i missing somthing ?
    thanks in advance.
  2. Answer
    Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 20 Sep 2011 Link to this post

    Hello Islam,

    DateTime supports 1753/1/1 to eternity (9999/12/31), while DateTime2 support 0001/1/1 through eternity. The DateTime2 range is the one that the DateTimePicker supports.
    So what you need to do is check for the year of the date - if it's before 1753, you need to change it to something after 1753 in order for the DateTime column in SQL Server to handle it.

    Hope this helps.

    Regards,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. DevCraft banner
  4. islam
    islam avatar
    4 posts
    Member since:
    Nov 2010

    Posted 20 Sep 2011 Link to this post

    Thanks Konstantina, yes that was the problem so i changed the datetime type in the database to datetime2 and it worked.
Back to Top