VBA date difference

You can use the DateDiff(interval, date1,date2[,firstdayofweek[,firstweekofyear]]) function to calculate the number
of days, months, weeks, quarters, hours, minutes, or second between two date values (date1 and date2).
-interval can be yyyy (year), m (month), d (day), q (quarter), ww (week), h (hour), n (minute), and s (second).
-date 1 is the first date.
-date2 is the second date.
-firstdayofweek (optional) specifies the start day of the week:
+1 Sunday (default)
+2 Monday
+3 Tuesday
+4 Wednesday
+5 Thursday
+6 Friday
-firstweekofyear(optional) specifies the first week of the year:
+1 Start with the week in which January 1 occurs (default)
+2 Start with the first week that has at least four days in the new year
+3 Start with the first full week of the year

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
     Dim ProStart, ProEnd
     ProStart = CDate("01-01-2013")
     ProEnd = CDate("02-03-2014")
     Range("C1") = DateDiff("d", ProStart, ProEnd) 'calculate the difference( in day) between ProStart and ProEnd

End Sub

Posted by: Lavy | post date: 02-20-2013 | Subject: VBA for MS Excel



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.