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
 General SQL Server Forums
 New to SQL Server Programming
 Manually Inserting date in a smalldatetime field

Author  Topic 

Blofeld
Starting Member

2 Posts

Posted - 2009-09-07 : 01:36:12
Hello,

I am trying to insert a date value in the database column which
has a column type of smalldatetime. I am using VWD2005 Express edition and SQLServer Express 2005 as the database.

I am trying to insert the values from a .net (C#) page. By using response.write i can always check the the value that i am trying to insert is correct, but in the db table its always getting inserted as "(Today's date) 12:00:00 AM" e.g. (9/7/2009 12:00:00 AM) although response.write will show the actual value that i am trying to insert, like "9/6/2009 5:35:00 AM"

varPreviousDate is a calculated value of date only to which i am concatenating a hard coded time value of "5:35:00 AM"

Here are some of the things i have tried so far:

varAutoTimeOut = Convert.ToString(varPreviousDate) + Convert.ToString(" 5:35:00 AM");

varAutoTimeOut = Convert.ToDateTime(varAutoTimeOut);

varAutoTimeOut is the value that i am trying to insert in the database.

Any help will be appreciated.

Thank you.



Blofeld
Starting Member

2 Posts

Posted - 2009-09-07 : 19:24:19
The problem was that my field type smalldatetime was rounding off my seconds to the closest minute as a result of which '9/6/2009 12:59:59 PM' was getting rounded to '9/7/2009 12:00:00 AM'. Probably i should've mentioned the actual value that i was trying to insert i.e. '9/6/2009 12:59:59 PM' instead '9/6/2009 5:35:00 AM' to make my question more clear. Now I have changed my field type in the database from smalldatetime to datetime and the query is working fine now.

Thanks.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-08 : 01:38:11
Thanks for posting the solution!
It might be helpful for others who do a search about a similar problem.



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -