472,958 Members | 2,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Week calculations (Date/Time)

Hello,

I'm looking for a function that returns a date range for a specified week
number of the year.

I'm not able to find functions like this anywhere. Any pointers/help would
be much appreciated.

TIA

Jim
Jul 19 '05 #1
2 5150
hi,
try these:

Microsoft® Visual Basic® Scripting Edition
DateDiff Function Language Reference
Version 2
See Also
----------------------------------------------------------------------------
----

Description
Returns the number of intervals between two dates.
Syntax
DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]])
The DateDiff function syntax has these parts:

Part Description
interval Required. String expression that is the interval you want
to use to calculate the differences between date1 and date2. See Settings
section for values.
date1, date2 Required. Date expressions. Two dates you want to use
in the calculation.
firstdayofweek Optional. Constant that specifies the day of the
week. If not specified, Sunday is assumed. See Settings section for values.
firstweekofyear Optional. Constant that specifies the first week of
the year. If not specified, the first week is assumed to be the week in
which January 1 occurs. See Settings section for values.

Settings
The interval argument can have the following values:
Setting Description
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week of year
h Hour
n Minute
s Second
The firstdayofweek argument can have the following values:

Constant Value Description
vbUseSystem 0 Use National Language Support (NLS) API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday
The firstweekofyear argument can have the following values:

Constant Value Description
vbUseSystem 0 Use National Language Support (NLS) API setting.
vbFirstJan1 1 Start with the week in which January 1 occurs
(default).
vbFirstFourDays 2 Start with the week that has at least four days in
the new year.
vbFirstFullWeek 3 Start with the first full weekof the new year.
Remarks
You can use the DateDiff function to determine how many specified time
intervals exist between two dates. For example, you might use DateDiff to
calculate the number of days between two dates, or the number of weeks
between today and the end of the year.
To calculate the number of days between date1 and date2, you can use
either Day of year ("y") or Day ("d"). When interval is Weekday ("w"),
DateDiff returns the number of weeks between the two dates. If date1 falls
on a Monday, DateDiff counts the number of Mondays until date2. It counts
date2 but not date1. If interval is Week ("ww"), however, the DateDiff
function returns the number of calendar weeks between the two dates. It
counts the number of Sundays between date1 and date2. DateDiff counts date2
if it falls on a Sunday; but it doesn't count date1, even if it does fall on
a Sunday.

If date1 refers to a later point in time than date2, the DateDiff function
returns a negative number.

The firstdayofweek argument affects calculations that use the "w" and "ww"
interval symbols.

If date1 or date2 is a date literal, the specified year becomes a
permanent part of that date. However, if date1 or date2 is enclosed in
quotation marks (" ") and you omit the year, the current year is inserted in
your code each time the date1 or date2 expression is evaluated. This makes
it possible to write code that can be used in different years.

When comparing December 31 to January 1 of the immediately succeeding
year, DateDiff for Year ("yyyy") returns 1 even though only a day has
elapsed.

The following example uses the DateDiff function to display the number of
days between a given date and today:

Function DiffADate(theDate)
DiffADate = "Days from today: " & DateDiff("d", Now, theDate)
End Function
DatePart Function Language Reference Version 2 See
Also -----------------------------------------------------------------------
-----DescriptionReturns the specified part of a given
date.SyntaxDatePart(interval, date[, firstdayofweek[, firstweekofyear]]) The
DatePart function syntax has these parts: Part Description interval
Required. String expression that is the interval of time you want to return.
See Settings section for values. date Required. Date expression you want to
evaluate. firstdayof week Optional. Constant that specifies the day of the
week. If not specified, Sunday is assumed. See Settings section for values.
firstweekofyear Optional. Constant that specifies the first week of the
year. If not specified, the first week is assumed to be the week in which
January 1 occurs. See Settings section for values. SettingsThe interval
argument can have the following values: Setting Description yyyy Year q
Quarter m Month y Day of year d Day w Weekday ww Week of year h Hour n
Minute s Second The firstdayofweek argument can have the following values:
Constant Value Description vbUseSystem 0 Use National Language Support (NLS)
API setting. vbSunday 1 Sunday (default) vbMonday 2 Monday vbTuesday 3
Tuesday vbWednesday 4 Wednesday vbThursday 5 Thursday vbFriday 6 Friday
vbSaturday 7 Saturday The firstweekofyear argument can have the following
values: Constant Value Description vbUseSystem 0 Use National Language
Support (NLS) API setting. vbFirstJan1 1 Start with the week in which
January 1 occurs (default). vbFirstFourDays 2 Start with the week that has
at least four days in the new year. vbFirstFullWeek 3 Start with the first
full weekof the new year. RemarksYou can use the DatePart function to
evaluate a date and return a specific interval of time. For example, you
might use DatePart to calculate the day of the week or the current hour. The
firstdayofweek argument affects calculations that use the "w" and "ww"
interval symbols. If date is a date literal, the specified year becomes a
permanent part of that date. However, if date is enclosed in quotation marks
(" "), and you omit the year, the current year is inserted in your code
each time the date expression is evaluated. This makes it possible to write
code that can be used in different years. This example takes a date and,
using the DatePart function, displays the quarter of the year in which it
occurs. Function GetQuarter(TheDate)
GetQuarter = DatePart("q", TheDate)
End Function
----------------------------------------------------------------------------
DateSerial Function Language Reference Version 1 See
Also -----------------------------------------------------------------------
-----DescriptionReturns a Variant of subtype Date for a specified year,
month, and day.SyntaxDateSerial(year, month, day) The DateSerial function
syntax has these arguments: Part Description year Number between 100 and
9999, inclusive, or a numeric expression. month Any numeric expression. day
Any numeric expression. RemarksTo specify a date, such as December 31, 1991,
the range of numbers for each DateSerial argument should be in the accepted
range for the unit; that is, 1-31 for days and 1-12 for months. However, you
can also specify relative dates for each argument using any numeric
expression that represents some number of days, months, or years before or
after a certain date. The following example uses numeric expressions instead
of absolute date numbers. Here the DateSerial function returns a date that
is the day before the first day (1 - 1) of two months before August (8 - 2)
of 10 years before 1990 (1990 - 10); in other words, May 31, 1980. Dim
MyDate1, MyDate2
MyDate1 = DateSerial(1970, 1, 1) ' Returns January 1, 1970.
MyDate2 = DateSerial(1990 - 10, 8 - 2, 1 - 1) ' Returns May 31, 1980.
For the year argument, values between 0 and 99, inclusive, are interpreted
as the years 1900-1999. For all other year arguments, use a complete
four-digit year (for example, 1800). When any argument exceeds the accepted
range for that argument, it increments to the next larger unit as
appropriate. For example, if you specify 35 days, it is evaluated as one
month and some number of days, depending on where in the year it is applied.
However, if any single argument is outside the range -32,768 to 32,767, or
if the date specified by the three arguments, either directly or by
expression, falls outside the acceptable range of dates, an error
occurs.DateValue Function Language Reference Version 1 See
Also -----------------------------------------------------------------------
---DescriptionReturns a Variant of subtype Date.SyntaxDateValue(date) The
date argument is normally a string expression representing a date from
January 1, 100 through December 31, 9999. However, date can also be any
expression that can represent a date, a time, or both a date and time, in
that range.RemarksIf the date argument includes time information, DateValue
doesn't return it. However, if date includes invalid time information (such
as "89:98"), an error occurs. If date is a string that includes only numbers
separated by valid date separators, DateValue recognizes the order for
month, day, and year according to the short date format you specified for
your system. DateValue also recognizes unambiguous dates that contain month
names, either in long or abbreviated form. For example, in addition to
recognizing 12/30/1991 and 12/30/91, DateValue also recognizes December 30,
1991 and Dec 30, 1991. If the year part of date is omitted, DateValue uses
the current year from your computer's system date. The following example
uses the DateValue function to convert a string to a date. You can also use
date literals to directly assign a date to a Variant variable, for example,
MyDate = #9/11/63#. Dim MyDate
MyDate = DateValue("September 11, 1963") ' Return a date.
--------------------------------------------------------------------------I
hope these help you!bye-- ««««««««»»»»»»»»»»»»»»Vlmar Brazăo de
OliveiraDesenvolvimento WebHI-TEC"androtech" <re********@thistoo.com>
escreveu na mensagem news:pa****************************@thistoo.com...
Hello,

I'm looking for a function that returns a date range for a specified week
number of the year.

I'm not able to find functions like this anywhere. Any pointers/help would
be much appreciated.

TIA

Jim

Jul 19 '05 #2
function GetweekDates(intYear,intWeek)
GetweekDates = "Error"
intYear = Trim(intYear)
intWeek = Trim(intWeek)
If IsNUmeric(intYear) And IsNumeric(intWeek) Then
If Len(intYear) = 4 And CDbl(intWeek) >= 0 And CDbl(intWeek) <= 52 Then
Dim ar(6)
dtmSetDate = DateAdd("ww",intWeek,DateSerial(intYear,1,1))
dtmSetDate = DateAdd("d",-(DatePart("w",dtmSetDate) - 1),dtmSetDate)
For i = 0 To 6
ar(i) = DateAdd("d",i,dtmSetDate)
Next
GetweekDates = Join(ar,",")
End If
End If
end function

-dlbjr

Discerning resolutions for the alms
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: lduperval | last post by:
Hi, I`m trying to do date calculations in three types of time zones: local, GMT and specified. The issue I am facing is that I need to be able to specify a date in the proper time zone, and I`m...
14
by: deko | last post by:
This runs, but does not narrow to current week. suggestions appreciated! SELECT lngEid, dtmApptDate, Subject, Appt_ID FROM qry002 WHERE (dtmApptDate BETWEEN DateAdd("d",-weekday()+2,) And...
4
by: Mark Reed | last post by:
Hi all, I am using office XP and have a question regarding the format function. I am using wk:format(.,"WW") to show what week a certain date is. The problem is that a week runs from Sun to Sat in...
5
by: Peter Bailey | last post by:
I have a query that returns , and : 12/05/04 3 Wednesday 13/05/04 0 Thursday and so on what I would like to do now is count the number of bookings by week so from monday to...
7
by: peter | last post by:
I have created a MS Access query where one of the fields displays the week number. The field is a date value that uses the ww format to display the week number. However, when I try to create a...
14
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity....
6
by: aarklon | last post by:
Hi folks, I found an algorithm for calculating the day of the week here:- http://www.faqs.org/faqs/calendars/faq/part1/index.html in the section titled 2.5 what day of the week was 2 august...
3
by: sbaird | last post by:
Aloha from Hawaii, I'm beating my head on the wall here. I have a recruiting contact managment database I'm trying to create. Managers (there ar 14 of them) have to make a certain number of...
9
Catalyst159
by: Catalyst159 | last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows: Part A: Maximum FAR and Floor Area: Part B: Gross Floor Area of...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.