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

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

2 Answers 648 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
islam
Top achievements
Rank 1
islam asked on 12 Sep 2011, 01:25 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Konstantina
Telerik team
answered on 20 Sep 2011, 06:59 AM
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 >>
0
islam
Top achievements
Rank 1
answered on 20 Sep 2011, 07:47 AM
Thanks Konstantina, yes that was the problem so i changed the datetime type in the database to datetime2 and it worked.
Tags
DatePicker
Asked by
islam
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
islam
Top achievements
Rank 1
Share this question
or