Date Parameters passed to stored procedure not working as expected
I faced an issue in my project where i passed the date as 09/03/2013
23:59:59 to stored procedure but saw in profiler .net converted it to
09/04/2013 00:00:00.
To confirm I created a small test application(anybody can use it to
replicate, I am using .Net 4.5 and Sql server 2012 express edition).
Below is test code:
DateTime startdate = DateTime.Parse("09/03/2013");
DateTime endDate = startdate.AddDays(1).AddTicks(-1);
try
{
using (SqlConnection konekcija = new
SqlConnection(ConfigurationManager.ConnectionStrings["default"].ToString()))
{
konekcija.Open();
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = konekcija;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "[Interface].[uspTestDateParameter]";
cmd.Parameters.AddWithValue("@CurrentDate", startdate);
cmd.Parameters.AddWithValue("@BatchEndDate", endDate);
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
// Fill the DataSet using default values for
DataTable names, etc
DataSet dataset = new DataSet();
da.Fill(dataset);
DataTable dt = dataset.Tables[0];
//return dataset;
}
}
}
}
catch (Exception ee)
{
}
Below is the procedure:
CREATE PROCEDURE [Interface].[uspTestDateParameter]
(
@CurrentDate DateTime
,@BatchEndDate DateTime
)
AS
BEGIN
Declare @table table (strt Datetime ,endT Datetime )
Insert into @table values (@CurrentDate,@BatchEndDate)
Select * from @table
END
The resultset returned is 9/3/2013 12:00:00 AM 9/4/2013 12:00:00 AM
I could have attached screen shot of Dataset visualizer but cannot do so
as it requires reputaion 10. but above are the values of two
columns(strt,enDt) I get.
Can somebody please help? My procs failing in production due to this.
No comments:
Post a Comment