Solved

Date calculation

Posted on 2003-03-14
Medium Priority
181 Views
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.

0
Question by:Lucy168
• 2

LVL 6

Accepted Solution

marconovaro earned 80 total points
ID: 8136677

Use the DateDiff function:

DateDiff("d", firstDate, secondDate )

M
0

LVL 33

Expert Comment

ID: 8136706
Try this

Dim mydate As Date
Dim newdate As Date

mydate = #19/06/2003#
MsgBox newdate

hongjun
0

LVL 33

Expert Comment

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

hongjun
0

LVL 1

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
0

Featured Post

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