how to insert date from textbox into database

Posted by Kishore463 under ASP.NET on 7/22/2013 | Points: 10 | Views : 1057 | Status : [Member] | Replies : 3
if we give year in textbox as 98 , it will print in database as 1998. how is it possible can any one explain




Responses

Posted by: Kmandapalli on: 7/23/2013 [Member] Silver | Points: 25

Up
0
Down
Hi,

In the database, in the column where you are saving the year, the datatype will be datatime in the format (YYYY-MM-DD)
and the default value of the year is 1900. So, when you give only date,, ie, for example:

DECLARE @time1 time(4) = '12:29:05.1234';
DECLARE @datetime2 datetime = @time1

SELECT @datetime2 AS 'datetimevar2'

Then the output will be as follows:
datetimevar2
1900-01-01 12:29:05.123

Execute the following query:


DECLARE @datetime1 datetime = '12-23-51';
DECLARE @time1 time(4) = '11:10:05.1234';
DECLARE @datetime2 datetime = @time1

SELECT @datetime1 AS 'datetime1', @datetime2 AS 'datetimevar2'

For datetime column, if you mention the year as any value below 50 (49,48,47........),
then the year in the output will be 2019, 2048, .....
Whereas if you give the value for the year above 49, then the output for the year will be in 19's ie, 1950, 1951, 1985, ................

That is the reason when you entering the year as 98, in is getting stored as 1998 in database...

Mark as Answr if satisfied............

Thank You,
Shree M.


Kavya Shree Mandapalli

Kishore463, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kishore463 on: 7/23/2013 [Member] Starter | Points: 25

Up
0
Down
Thank You very much to your response

Kishore463, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kmandapalli on: 7/24/2013 [Member] Silver | Points: 25

Up
0
Down
Hi,

Can you please mark it as answer.........

Thank,
Shree M.

Kavya Shree Mandapalli

Kishore463, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response