Author |
Topic |
Malathe.A.
Starting Member
10 Posts |
Posted - 2009-03-05 : 01:47:03
|
Hello, I'm trying to use datetime format in my project. When i insert any date, the date is stored in database as 1900-01-01 00:00:00.000. How to reset this date in sql server??? |
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2009-03-05 : 10:55:20
|
your application is not sending the date value correctly. If you just want to use current datetime you can use Getdate() in your T-SQL.Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
Malathe.A.
Starting Member
10 Posts |
Posted - 2009-03-05 : 11:45:50
|
If i try to insert the date value directly using an insert query without using the application, the record gets inserted. But if i retrieve the records the date value is set as 1900-01-01 00:00:00.000. Can u suggest me a solution.. |
 |
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2009-03-05 : 14:00:08
|
If the value in your table is correct, then your application isnt reading it properly. I remember I used to get these values few years back when I wrote .NET code. The datatypes in your application should match with those in the database. The value is getting lost in translation, I believe.Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
Malathe.A.
Starting Member
10 Posts |
Posted - 2009-03-07 : 13:06:35
|
I didnt even use .NET application to insert a record. I'm just trying to insert a record directly to the database without an application. The date field in the record is stored as 1900-01-01 00:00:00.000 in the database. Actually the problem is with the database i think. Is there any default date settings in SQL Server 2005?? |
 |
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2009-03-07 : 20:11:11
|
Can you provide some code?Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
Malathe.A.
Starting Member
10 Posts |
Posted - 2009-03-08 : 09:44:57
|
SqlCommand insertComm = new SqlCommand("INSERT INTO [BankDB].[dbo].[Transaction] ([AccountNumber],[ToAccountNumber],[transDate],[transactionType],[transactionAmount],[chequeNumber]) VALUES ('123012345','123010000','" + dt + "' ,'Debit',25000,'12301234568')", con1); insertComm.Connection = con1; insertComm.Connection.Open();Here dt is variable having d current date.. I used this command to insert the date value.. But the value stored in the database is 1900-01-01 00:00:00.000. |
 |
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2009-03-09 : 10:17:38
|
Why dont you just do this instead?("INSERT INTO [BankDB].[dbo].[Transaction] ([AccountNumber],[ToAccountNumber],[transDate],[transactionType],[transactionAmount],[chequeNumber]) VALUES ('123012345','123010000', getdate() ,'Debit',25000,'12301234568')",Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
Malathe.A.
Starting Member
10 Posts |
Posted - 2009-03-10 : 10:22:07
|
Thank you for your suggestion.. I found out that if we use a calendar control and insert the calendar.selectedvalue, the date is inserted in the correct format.. |
 |
|
|