how to get the number of days between two date formatted fields in vba for excel?

D

David McRitchie

Hi Daniel,
If they are Excel dates they represent the days and fractional days past
Dec 31, 1899 if using the 1900 date system. So if you just have dates
they have no fractional components and you just subtract the earlier
date from the later date for the number of days. So it doesn't really
matter if it is Excel or VBA same method.

A1: 1998-11-28 B1: 2005-07-11 C1: =B1-A1
format c1 as number: #,##0
otherwise you will see: 1906-08-13

in VBA something like either of these, no formatting required
[c1] = [b1] - [a1]
Cells(1,3).value = Cells(1,2).value - Cells(1,1).value

More information on Date and Time in (two pages are not much alike)
http://www.mvps.org/dmcritchie/excel/datetime.htm
http://www.cpearson.com/excel/datetime.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top