4
using System.Data;
using System.Data.SqlClient;

I am using a SqlCommand cmd.Parameters of SqlDbType.DateTime to create a record in the database.

Seconds are not being stored in the database. The field in the db is of type datetime.

Do I need to do something special to save seconds, or does SqlDbType.DateTime not do that?

Nikhil Vartak
  • 5,002
  • 3
  • 26
  • 32
Lill Lansey
  • 4,775
  • 13
  • 55
  • 77

2 Answers2

4

SqlDbType.DateTime maps to SQL's DATETIME datatype, which is accurate to 3.33 milliseconds. It sounds like you may be putting your values into a SMALLDATETIME field in SQL server, which is only accurate to the minute. SqlDbType.DateTime parameter would be the correct choice for use with both DATETIME and SMALLDATETIME.

Safa
  • 178
  • 1
  • 12
Scott Ivey
  • 40,768
  • 21
  • 80
  • 118
0

SQL Server DateTime stores time with millisecond accuracy (not quite right it rounds to .003 .007 etc)

Smalldatetime, however, stores dates such that the seconds are always :00. You have probably used smalldatetime.

http://msdn.microsoft.com/en-us/library/ms182418.aspx

Shiraz Bhaiji
  • 64,065
  • 34
  • 143
  • 252