?
Solved

How to get number of weeks and days between two dates in Access VBA

Posted on 2009-05-15
4
Medium Priority
?
1,243 Views
Last Modified: 2013-11-27
I would like code that will show the number of weeks and days between two dates.  For example - April 8, 2009 (wed) through May 11, 2009 (Mon) would show 4 weeks 5 days.

The 4 would be stored in a field called weeks and the 5 would be stored in days, or even catenate them as a value "4 weeks 5 days" in a database field.  This solution is needed for calendar days; however, it would also be neat to know it on a work week (M-F) type and become 4 weeks and 3 days.

Another way to state this:  (This should count the number of Wednesdays [4/15, 4/22, 4/29, 5/06] = 4 WEEKS coming up to May 11 and adds the remaining days to get to that date as days THURS [5/07], FRIDAY[5/08], SAT[5/09], SUN[5/10], MON-[5/11 target date] (5 days) CALENDAR type and a solution for the optional way THURS [5/07], FRIDAY[5/08], MON-[5/11 target date] (3 days) for WORK WEEK type.)

Any ideas and workable sub/function would be great.
0
Comment
Question by:HRISTeam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 93

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 400 total points
ID: 24397330
Hello HRISTeam,

Assuming your dates have no time portions...

SELECT Date1, Date2, Int(DateDiff("d", Date1, Date2) / 7) & " weeks " & (DateDiff("d", Date1, Date2) Mod 7) & " days"
FROM SomeTable

Regards,

Patrick
0
 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 400 total points
ID: 24397351
You could use DateDiff to return the number of days

syntax is

DateDiff("d", firstdate, seconddate)

Given this you can then divide by 7 to get weeks and remainder is days

eg using d1 and d2 as dates

NumberOfWeeks = Round((DateDiff("d", d1, d2) / 7) - 0.5)
NumberOfDays = DateDiff("d", d1, d2) Mod 7
0
 
LVL 44

Assisted Solution

by:GRayL
GRayL earned 400 total points
ID: 24397370
try this:

datediff("d",#04-08#,#05-11#)\7 & " weeks " & datediff("d",#04-08#,#05-11#) mod 7 & " days "

0
 
LVL 1

Accepted Solution

by:
HRISTeam earned 0 total points
ID: 24397577
Thanks for the fast response.  I will try each of them alittle later (have a meeting to go to which could be long), if they all work, you all will get some points.
0

Featured Post

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

762 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