Home All Groups Group Topic Archive Search About

Milliseconds are truncated when inserting DatTime in Sql Server

Author
27 Feb 2006 8:37 PM
eacsub
check the InternalTicks for the date1 and date and see what I mean. What the
hell?

string connString = "Data Source=(local);Initial Catalog=Test;Integrated
Security=True";
        SqlCommand command = new SqlCommand("insert into Table_1
(CreateDate) values (@date)");
        DateTime date1 = DateTime.Now;
        command.Parameters.AddWithValue("@date", date1);

        command.Connection = new SqlConnection(connString);

        command.Connection.Open();
        command.ExecuteNonQuery();       

        command.CommandText = "Select * from Table_1";
        SqlDataReader reader = command.ExecuteReader();
        reader.Read();
        DateTime date = (DateTime)reader["CreateDate"];
        reader.Close();


        command.CommandText = "Delete from Table_1";
        command.ExecuteNonQuery();
        command.Connection.Close();

Author
28 Feb 2006 1:01 AM
Jim Hughes
SQL Server only stores seconds with 1/3 second precision.

http://vyaskn.tripod.com/searching_date_time_values.htm

Show quote
"eacsub" <eac***@discussions.microsoft.com> wrote in message
news:666CA79E-F1BF-4AD5-A06F-4208FBBBC77F@microsoft.com...
> check the InternalTicks for the date1 and date and see what I mean. What
> the
> hell?
>
> string connString = "Data Source=(local);Initial Catalog=Test;Integrated
> Security=True";
>        SqlCommand command = new SqlCommand("insert into Table_1
> (CreateDate) values (@date)");
>        DateTime date1 = DateTime.Now;
>        command.Parameters.AddWithValue("@date", date1);
>
>        command.Connection = new SqlConnection(connString);
>
>        command.Connection.Open();
>        command.ExecuteNonQuery();
>
>        command.CommandText = "Select * from Table_1";
>        SqlDataReader reader = command.ExecuteReader();
>        reader.Read();
>        DateTime date = (DateTime)reader["CreateDate"];
>        reader.Close();
>
>
>        command.CommandText = "Delete from Table_1";
>        command.ExecuteNonQuery();
>        command.Connection.Close();
Author
28 Feb 2006 3:00 AM
Stephany Young
Close! It's 3 millisecond precision.


Show quote
"Jim Hughes" <NOSPAMJ3033@Hotmail.com> wrote in message
news:u0aayJAPGHA.3864@TK2MSFTNGP10.phx.gbl...
> SQL Server only stores seconds with 1/3 second precision.
>
> http://vyaskn.tripod.com/searching_date_time_values.htm
>
> "eacsub" <eac***@discussions.microsoft.com> wrote in message
> news:666CA79E-F1BF-4AD5-A06F-4208FBBBC77F@microsoft.com...
>> check the InternalTicks for the date1 and date and see what I mean. What
>> the
>> hell?
>>
>> string connString = "Data Source=(local);Initial Catalog=Test;Integrated
>> Security=True";
>>        SqlCommand command = new SqlCommand("insert into Table_1
>> (CreateDate) values (@date)");
>>        DateTime date1 = DateTime.Now;
>>        command.Parameters.AddWithValue("@date", date1);
>>
>>        command.Connection = new SqlConnection(connString);
>>
>>        command.Connection.Open();
>>        command.ExecuteNonQuery();
>>
>>        command.CommandText = "Select * from Table_1";
>>        SqlDataReader reader = command.ExecuteReader();
>>        reader.Read();
>>        DateTime date = (DateTime)reader["CreateDate"];
>>        reader.Close();
>>
>>
>>        command.CommandText = "Delete from Table_1";
>>        command.ExecuteNonQuery();
>>        command.Connection.Close();
>
>
Author
28 Feb 2006 5:41 AM
Jim Hughes
Whoops, you are right of course... Glad I included a link :)

Show quote
"Stephany Young" <noone@localhost> wrote in message
news:%231yUqMBPGHA.2040@TK2MSFTNGP14.phx.gbl...
> Close! It's 3 millisecond precision.
>
>
> "Jim Hughes" <NOSPAMJ3033@Hotmail.com> wrote in message
> news:u0aayJAPGHA.3864@TK2MSFTNGP10.phx.gbl...
>> SQL Server only stores seconds with 1/3 second precision.
>>
>> http://vyaskn.tripod.com/searching_date_time_values.htm
>>
>> "eacsub" <eac***@discussions.microsoft.com> wrote in message
>> news:666CA79E-F1BF-4AD5-A06F-4208FBBBC77F@microsoft.com...
>>> check the InternalTicks for the date1 and date and see what I mean. What
>>> the
>>> hell?
>>>
>>> string connString = "Data Source=(local);Initial Catalog=Test;Integrated
>>> Security=True";
>>>        SqlCommand command = new SqlCommand("insert into Table_1
>>> (CreateDate) values (@date)");
>>>        DateTime date1 = DateTime.Now;
>>>        command.Parameters.AddWithValue("@date", date1);
>>>
>>>        command.Connection = new SqlConnection(connString);
>>>
>>>        command.Connection.Open();
>>>        command.ExecuteNonQuery();
>>>
>>>        command.CommandText = "Select * from Table_1";
>>>        SqlDataReader reader = command.ExecuteReader();
>>>        reader.Read();
>>>        DateTime date = (DateTime)reader["CreateDate"];
>>>        reader.Close();
>>>
>>>
>>>        command.CommandText = "Delete from Table_1";
>>>        command.ExecuteNonQuery();
>>>        command.Connection.Close();
>>
>>
>
>

AddThis Social Bookmark Button