Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate Number of Weeks Between Two Dates 1

Status
Not open for further replies.

needadvice

Programmer
Joined
Apr 7, 2002
Messages
145
Location
US
Can someone give me the VB for calculating the number of weeks between two dates.
Thanks in advance.
 
DateDiff("ww",Date1,Date2)

This will return the number of weeks between the two dates.

Depending on where you live , the first day of the week may not be Sunday. If this is the case, the expression would be:

DateDiff(ww,Date1,Date2,vbMonday)

or whatever day you want. ( Personally, I don't know of anyplace that doesn't have Sunday or Monday as the first day in the week, but you never know... )


Robert
 
That last one should be

DateDiff("ww",Date1,Date2,vbMonday)

,instead. ( forgot the quotes... )

Robert
 
TheVampire,
Lots of Middle East countries will use Saturday as the first day of the week. Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
That worked good. What I need this for is to count the number of weeks between to dates and then duplicate a record that many times (-1) in the table. The first record is being created in a DataEntry form. It is ultimatley to produce a schedule of payment report.
This is a little more involved.
Can you help with this.
I'm not proficient in VB and need to know if a loop statement is what is needed here. An example would be very usefull to me.
Thanks.
 
The only problem with the datediff is that it calculates intervals only.

So:

?DateDiff("ww", #09/29/02#, #09/30/02#, vbMonday)

Will return an answer of 1 week, even though only one day has passed.

Try this instead:

Dim Date1 As String
Dim Date2 As String

Date1 = rsData.DateFrom
Date2 = rsData.DateTo

Weeks = Int(DateDiff("d", Date1,Date2)/7)

Or:

Dim Date1 As Date
Dim Date2 As Date

Date1 = rsData.DateFrom
Date2 = rsData.DateTo

Weeks = Int((Date1-Date2)/7) [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Thanks, That helped me develop the payment schedule based on these two dates.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top