Date calculation

Posted on 2003-03-14
Medium Priority
Last Modified: 2010-05-01
I have a date calculation. How do you calculate any two dates (but in the same year) to find the number of days. The date format is: DD/MM/YYYY. For example, 19/06/2003 - 23/04/2003. And How do you add on nine months (in the format: DD/MM/YYYY) to a date to get the accurate date?

An accurate date must be given, i.e. need to take into account that some months have different number of days.

Question by:Lucy168
  • 2

Accepted Solution

marconovaro earned 80 total points
ID: 8136677

Use the DateDiff function:

DateDiff("d", firstDate, secondDate )

and use DateAdd to add months:

DateAdd("m", 9, startDate)

LVL 33

Expert Comment

ID: 8136706
Try this

Dim mydate As Date
Dim newdate As Date

mydate = #19/06/2003#
newdate = DateAdd("m", 9, mydate)
MsgBox newdate

LVL 33

Expert Comment

ID: 8136713
OOPS. Did not see your comment before I post mine.


Expert Comment

ID: 8137776
With your format being DD/MM/YYYY, it might get crazy trying to get number of days between dates!  You could re-format dates in order to get accurate time frame between the dates.

You could use the following to obtain the number of days between 2 dates(If format was MM/DD/YYYY or YYYY/MM/DD)

Dim NumDays%

NumDays = format(format(Date1,"YYYY/MM/DD"),"#") - format(format(Date2,"YYYY/MM/DD"),"#")
msgbox NumDays

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question