Click here to Skip to main content
15,607,111 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a column date which has the values with date and its coressponding time stamp
but the query with which I am querying the table has a between which has 2 date values

eg 2014-06-24 00:00:00 and 2014-06-26 00:00:00

So the query retrieves the result only for 24,25 but not for 26 as the time is for midnight.
So is there any way to convert 00:00:00 in date2 to 23:59:59 using C#
Updated 20-Apr-21 23:34pm
ArunRajendra 27-Jun-14 5:28am    
Post the code what you have tried.

Share this answer
VipinKumar Maurya 27-Jun-14 5:30am    
That what I am not getting it. How to do it?
you may try with
toDate.ToString("yyyy-MM-dd 23:59:59.000");

DECLARE @Time TIME = '23:59:59.999'
SELECT dateColumn + CAST(@Time as DATETIME)
FROM tableName
Share this answer
VipinKumar Maurya 28-Jun-14 2:36am    
Thanks to all. I got my work done
assume you have two date times as parameters to your search method, for example startdt, enddt
what you can do is, set end date by adding one day like below
enddt = enddt.AddDays(1);

now call your function with startdt, enddt
Share this answer
Some time ago I've answered similar question. Simples way is to forget about Time part and use only date part. Maybe my solution will help you:

how to query for date in between for window forms in c#[^]
Share this answer
Declare two DateTime variables as below:

DateTime dtFromDate = DateTime.Now.Date;// You will get date as DD-MM-YYYY 12:00:00 AM
DateTime dtFrom  =DateTime.Now.AddDays(1).Date.AddSeconds(-1);// You will get date as DD-MM-YYYY 23:59:59 PM
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900