Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Date Insert Problem

Author  Topic 

marchawinslet
Starting Member

11 Posts

Posted - 2006-08-19 : 07:19:11
This simple insert works fine for me from QA:

INSERT INTO tbl_Test(Joining_Date, Group_number) values('08/18/2001' ,'9')

HOWEVER when I do the insert from my ASP.Net application the date in the table is '01/01/1900'

Obviously it is reverting to some default date. Why? How do I fix it?

Marcha x

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-08-19 : 08:01:13
Just check the format of the Date which you are passing from your front end.



Chirag
Go to Top of Page

marchawinslet
Starting Member

11 Posts

Posted - 2006-08-19 : 08:07:30
I think the formatting is OK. '08/18/2001' works fine but '18/08/2001' gives an error, which is what I expected because it is set up for US dates. Where and how is the value 01/01/1900 being generated? It doesn't seem to be at the front end because if I post it to another page it appears fine.
Many thanks for any help.
Marcha x
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-08-19 : 08:30:22
According to me the following are the ways due to which the date is set to 1900-01-01

1) When you try to insert the values in the datetime column, with blank spaces somthing like this.
Insert <Table> ( DtDateTime)
Select ''


2) If the Default date is set, but since you are specifying the date in the insert statement so it will explicitly pick the value which you are passing and not take the default date.

3) Due to any constraints on the Column. for instance if the date range between xx to yy then set it to default date.

4)Via Triggers.


When ever you are using ASP.Net is always good to use Stored Procdure for any DML statements. so try to make this insert statement using stored procedure.

Chirag
Go to Top of Page

mahesh_bote
Constraint Violating Yak Guru

298 Posts

Posted - 2006-08-19 : 09:31:11
INSERT INTO tbl_Test(Joining_Date, Group_number) values(FormatDateTime("<value>", DateFormat.ShortDate),'9')

use this


Mahesh
Go to Top of Page

marchawinslet
Starting Member

11 Posts

Posted - 2006-08-19 : 18:50:11
Thanks guys I used the advice from both of you. Set up a stored procedure and changed the date formatting in the application and all is working fine now.
Very grateful, Marcha
Go to Top of Page
   

- Advertisement -