calculating number of days between two dates

Can anyone show me how to create a vb function that will allow me to take two dates which are stored in a database, and then determine the numbers of days in between them?

Any help would be greatly appreciated.
Thanks
0
afelicetti
1/13/2004 4:59:58 PM
📁 asp.net.web-forms
📃 93655 articles.
⭐ 5 followers.

💬 3 Replies
👁️‍🗨️ 688 Views


dim diff as integer = date1.DayOfYear - date.DayOfYear

Hope this helps!



GRJ
0
grj
1/13/2004 5:56:58 PM

Use DateDiff function:

Dim diff as Integer = DateDiff(DateInterval.Day, Date1, Date2)

Parameter DateInterval.Day return result in days, but there are too:
DateInterval.Month
DateInterval.Year
DateInterval.Hour
DateInterval.Minute
....

Ângelo Paulo
0
angelo
1/13/2004 6:15:27 PM
I have an ASP.NET application that schedules/reserves items for a block of time in days.  Here is the code that I use to determine the number of days from two date strings that were input from textbox fields in my form:


Private Function NumberOfDaysRequested(ByVal startDate as string, endDate as string) As Int
{
Dim startDate as DateTime
Dim endDate as DateTime
Dim dateDiff as TimeSpan
startDate = DateTime.Parse(startDate)
endDate = DateTime.Parse(endDate)
dateDiff = endDate.Subtract(startDate)
return dateDiff.Days
}
0
sierrakilo
1/14/2004 12:50:01 AM
Reply: