TechArena Community Calculating difference in days between two dates in Asp.Net

#1
07-07-2009
 Member Join Date: Jan 2009 Posts: 44
Calculating difference in days between two dates in Asp.Net

I am having trouble in calculating difference in days between two dates in Asp.Net Can anyone provide me with the logic? Or the code will be much better. Please help Guys!
#2
07-07-2009
 Member Join Date: May 2008 Posts: 2,008
Re: Calculating difference in days between two dates in Asp.Net

Are you using SQL database in your project? If yes then it can be used to perform this calculations. SQL has a function called DATEDIFF.
Syntax :
Code:
`DATEDIFF ( datepart , startdate , enddate )`
Hope this is useful, All the best!
#3
07-07-2009
 Member Join Date: Apr 2008 Posts: 2,001
Re: Calculating difference in days between two dates in Asp.Net

May be you should try this out :

Code:
```DateTime date1 = new DateTime.Now;
DateTime date2 = new DateTime(2009,1,1)
TimeSpan ts;
ts = date1.Subtract(date2.Date);```
Is this what you are looking for?
#4
07-07-2009
 Member Join Date: May 2008 Posts: 2,383
Re: Calculating difference in days between two dates in Asp.Net

The following code may do the work, have a try :

Code:
```Dim datTim1 As Date = #7/7/2009#
Dim datTim2 As Date = #7/10/2009#
Dim wD As Long = DateDiff(DateInterval.Weekday, DatTim1, DatTim2)
Dim wY As Long = DateDiff(DateInterval.WeekOfYear, DatTim1, DatTim2)```

 Similar Threads for: "Calculating difference in days between two dates in Asp.Net" Thread Thread Starter Forum Replies Last Post Calendar days vs work days Boerseun Microsoft Project 4 02-07-2014 10:28 PM Converting work days to calendar days TheTurner Microsoft Project 12 02-07-2014 10:15 PM Program to calculate days difference between two dates in java. KADRI Software Development 5 16-03-2011 06:22 PM Changing Calendar to count all days and not only BUSINESS days M Moreno Microsoft Project 3 12-01-2011 05:05 AM find period in days / hours excluding weekdays between two days? Segvoia Software Development 3 19-06-2009 11:17 AM

All times are GMT +5.5. The time now is 01:00 PM.