Reputation: 16219
I know this might be duplicate but code is still not working for me in c#.
I want to convert datetime format to 00:00:00 instead of 12:00:00
I tried like
cmd.Parameters.Add(new SqlParameter("@fromDate", dtFromDate.Date.ToString("yyyy-MM-dd HH:mm:ss")));
but not working for me :(
please correct me.
Upvotes: 2
Views: 2865
Reputation: 4057
Using native datetime would be better practice I think
cmd.Parameters.Add(new SqlParameter("@fromDate", dtFromDate.Date)
Upvotes: 1
Reputation: 8626
Change H:mm:ss instead of hh:mm:ss in the format string.
H represents the hour as a number between 0 and 23 , hh represents the hour as a number between 01 and 12.
dtFromDate.Date.ToString("yyyy-MM-dd H:mm:ss")));
i.e. it should look like:
cmd.Parameters.Add(new SqlParameter("@fromDate", dtFromDate.Date.ToString("yyyy-MM-dd H:mm:ss")));
This will work.
Upvotes: 10