AJM
AJM

Reputation: 32490

C# DateTime vs SQL Server Date - type in stored procedure

If I have a C# DateTime object and a column in SQL Server of type Date (not DateTime)

For a stored procedure that takes in the date time from C# do I have any option other than passing in the C# DateTime as a SQL Server DateTime or can I pass it in of type Date?

Upvotes: 0

Views: 757

Answers (2)

Adriaan Stander
Adriaan Stander

Reputation: 166406

You could always use the DateTime.Date Property

Gets the date component of this instance.

Upvotes: 0

marc_s
marc_s

Reputation: 754598

Define it as a DATE in your stored procedure

CREATE PROCEDURE dbo.YourProcedure (@FromDate DATE)
.....

and call it like this from C#:

yourSqlCmd.Parameters.Add("@FromDate", SqlDbType.Date);
yourSqlCmd.Parameters["@FromDate"].Value = yourDotNetDateTime.Date;

Upvotes: 1

Related Questions