Skip to content

Change in handling of Date/DateTime values after migration from v1.0.19269.1 to v1.1.1. #434

@dev-ska

Description

@dev-ska

On v1.0: the DbType.Date parameter, which has a DateTime value, is saved as a DateTime in the database.
On v1.1: the DbType.Date parameter, which has a DateTime value, is saved as a Date in the database (a time part is truncated).
The database column is of type datetime2.

Table declaration:

CREATE TABLE SqlClientTest
(
	DateTimeColumn datetime2 NOT NULL
)
GO

Code:

using (var connection = new SqlConnection(connectionString))
{
	var command = new SqlCommand($"insert into SqlClientTest (DateTimeColumn) values (@value)", connection);
	var parameter = command.CreateParameter();

	parameter.ParameterName = "@value";
	parameter.Value = DateTime.Now;
	parameter.DbType = DbType.Date;

	command.Parameters.Add(parameter);

	connection.Open();
	command.ExecuteNonQuery(); // running on v1.1, DateTimeColumn has no time part
	connection.Close();
}

Was this a functional change?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions