By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,635 Members | 2,188 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,635 IT Pros & Developers. It's quick & easy.

Week calculations (Date/Time)

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.