Subtrating two dates to calculate number of days
how to subtract two datetime without subtracting time?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Iftikar HussainPosted Jul 16, 2013, 5:45 AM
Regards,
Iftikar
Sanjeeb LenkaPosted Jul 16, 2013, 5:36 AM
your code is giving the correct answer. no or days between current day and input day.
so what the problem you are getting.
Nahul AntonyPosted Jul 16, 2013, 5:26 AM
double s1;
double s2;
DateTime dt = System.DateTime.Today;
DateTime dt1 = dtpDate.Value;
ts = (dt - dt1);
s1 = Convert.ToDouble(ts.TotalDays);
//s2 = Convert.ToDouble(ts.TotalMinutes);
txtTotDays.Text = Convert.ToString(s1);
i not need to subtract time.i need date to subtract from datetime
Sanjeeb LenkaPosted Jul 16, 2013, 5:25 AM
DateTime d1=Convert.ToDateTime("12/22/2013");
DateTime d2 = Convert.ToDateTime("12/22/2012");
var d = (d1 - d2).TotalDays;
output:365
Nahul AntonyPosted Jul 16, 2013, 5:24 AM
Nahul AntonyPosted Jul 16, 2013, 5:21 AM
Iftikar HussainPosted Jul 16, 2013, 5:20 AM
Can you provide your example?
Regards,
Iftikar
Nahul AntonyPosted Jul 16, 2013, 5:17 AM
Jignesh TrivediPosted Jul 16, 2013, 5:10 AM
hi,
Are you looking in SQL or C#?
if it is in C# than agree with above answer
if you look in SQL than try
select DATEDIFF(d,'2013-05-20 12:12:45','2013-07-20 15:12:45')
hope this will help you.
VulpesPosted Jul 16, 2013, 4:56 AM
Sanjeeb LenkaPosted Jul 16, 2013, 4:30 AM
difference.TotalDayswill give you number of days