473,395 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 5186
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.