473,748 Members | 2,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How determine what day of the week a certain date is?

I have two problems, actually. I am looking to see if there is a
function that will return the day of the week (Monday, Tuesday,
Wednesday, etc...) from a date. For instance 2/27/04 is a Friday.

Also is there a way to group dates by week? I have a user who wants a
report to group by week. I know I could create a table and assign
dates to a week, but I'm wondering if anyone has anything out there
already done that may be a little bit simpler.

Thanks!

Pamela
Nov 12 '05 #1
9 7283
Off the top of my head, I've never seen anything that will will return
Friday or Monday, but it wouldn't be to hard to make a function that does
this. The only problem will be if regional settings affect what day is
considered the first.

Function GetDayName(useD ate as Date) As String
Dim dayNum as Integer

If Not IsDate(useDate) Then Exit Function
dayNum = DatePart("w",Da te)
Select Case dayNum
Case 1
GetDayName = "Sunday"
Case 2
GetDayName = "Monday"
Case 3
GetDayName = "Tuesday"
etc...

End Select
End Function

As for the second question, you can get the week number (1-53 I beleive) by
using DatePart("ww",D ate). Perhaps this number could be used to sort or
group on in a query. Alternatively, you'd have to use a range as a string as
the sorting grouping value ie. "02/01/04 - 05/25/04.

Mike Storr
www.veraccess.com
"PamelaDV" <pd******@steel case.com> wrote in message
news:b6******** *************** ***@posting.goo gle.com...
I have two problems, actually. I am looking to see if there is a
function that will return the day of the week (Monday, Tuesday,
Wednesday, etc...) from a date. For instance 2/27/04 is a Friday.

Also is there a way to group dates by week? I have a user who wants a
report to group by week. I know I could create a table and assign
dates to a week, but I'm wondering if anyone has anything out there
already done that may be a little bit simpler.

Thanks!

Pamela

Nov 12 '05 #2
For day of week try Format$(NOW()," dddd")

In your report, use SORTING AND GROUPING to sort on the date field, then set
GROUP ON to "Week".
If you also want to sort the days of the week, setup a 2nd sort on the same
date field and set GROUP ON to "Each value".

"PamelaDV" <pd******@steel case.com> wrote in message
news:b6******** *************** ***@posting.goo gle.com...
I have two problems, actually. I am looking to see if there is a
function that will return the day of the week (Monday, Tuesday,
Wednesday, etc...) from a date. For instance 2/27/04 is a Friday.

Also is there a way to group dates by week? I have a user who wants a
report to group by week. I know I could create a table and assign
dates to a week, but I'm wondering if anyone has anything out there
already done that may be a little bit simpler.

Thanks!

Pamela

Nov 12 '05 #3
Check the help files for WeekDay().

--
=============== ==
Jeremy Wallace
AlphaBet City Dataworks
ABCDataworks dot com
"PamelaDV" <pd******@steel case.com> wrote in message
news:b6******** *************** ***@posting.goo gle.com...
I have two problems, actually. I am looking to see if there is a
function that will return the day of the week (Monday, Tuesday,
Wednesday, etc...) from a date. For instance 2/27/04 is a Friday.

Also is there a way to group dates by week? I have a user who wants a
report to group by week. I know I could create a table and assign
dates to a week, but I'm wondering if anyone has anything out there
already done that may be a little bit simpler.

Thanks!

Pamela

Nov 12 '05 #4
On 4 Mar 2004 12:20:16 -0800, pd******@steelc ase.com (PamelaDV) wrote:
I have two problems, actually. I am looking to see if there is a
function that will return the day of the week (Monday, Tuesday,
Wednesday, etc...) from a date. For instance 2/27/04 is a Friday.
See help for the Format() function.
Also is there a way to group dates by week? I have a user who wants a
report to group by week. I know I could create a table and assign
dates to a week, but I'm wondering if anyone has anything out there
already done that may be a little bit simpler.


Best Practice is to use a table.

--
Mike Sherrill
Information Management Systems
Nov 12 '05 #5
pd******@steelc ase.com (PamelaDV) wrote in news:b6783f18.0 403041220.39301 038
@posting.google .com:
Also is there a way to group dates by week? I have a user who wants a
report to group by week. I know I could create a table and assign
dates to a week, but I'm wondering if anyone has anything out there
already done that may be a little bit simpler.


An expression like

DatePart("ww", vDate, vbSunday, vbFirstJan1)

can return a week of the year.

The enumerators vbSunday, vbFirstJan1 can be manipulated to modify the
results in keeping with your local practice.

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #6
CDB
Or WeekDayName() function.

I followed Mike's suggestion of using a table a few years back, and it has
proved to be invaluable. The only system I know which handles the week
across the year change is the ISO system. My USA clients seem entirely happy
with the result - they probably do not realise that it is (gasp)
International!

Clive
"Mike Sherrill" <MS************ *@compuserve.co m> wrote in message
news:jp******** *************** *********@4ax.c om...
On 4 Mar 2004 12:20:16 -0800, pd******@steelc ase.com (PamelaDV) wrote:
I have two problems, actually. I am looking to see if there is a
function that will return the day of the week (Monday, Tuesday,
Wednesday, etc...) from a date. For instance 2/27/04 is a Friday.


See help for the Format() function.
Also is there a way to group dates by week? I have a user who wants a
report to group by week. I know I could create a table and assign
dates to a week, but I'm wondering if anyone has anything out there
already done that may be a little bit simpler.


Best Practice is to use a table.

--
Mike Sherrill
Information Management Systems

Nov 12 '05 #7
On 6 Mar 2004 13:48:07 GMT, Lyle Fairfield <Mi************ @Invalid.Com> wrote:
pd******@steel case.com (PamelaDV) wrote in news:b6783f18.0 403041220.39301 038
@posting.googl e.com:
Also is there a way to group dates by week? I have a user who wants a
report to group by week. I know I could create a table and assign
dates to a week, but I'm wondering if anyone has anything out there
already done that may be a little bit simpler.


An expression like

DatePart("ww ", vDate, vbSunday, vbFirstJan1)

can return a week of the year.

The enumerators vbSunday, vbFirstJan1 can be manipulated to modify the
results in keeping with your local practice.

Q200299 BUG: Format or DatePart Functions Can Return Wrong Week Number for Last Monday in Year

The article includes a function which returns the correct weeknumber to the ISO standard.
Wayne Gillespie
Gosford NSW Australia
Nov 12 '05 #8
CDB
Plus the wrong year, in certain cases. It was worse pre-A2K! Here is my
solution:

Public Function getISODate(varD ate As Variant) As String
'revised 13/5/03 to patch bug in Oleaut32.dll
Dim dtDate As Date
Dim intYear As Integer
Dim intWeek As Integer
Dim intDay As Integer
Dim intDayOfYear As Integer
Dim strRslt As String
On Err GoTo procerr
strRslt = "0000000"
If IsDate(varDate) Then
dtDate = CDate(varDate)
intYear = Year(dtDate)
If DatePart("ww", dtDate + 7, vbMonday, vbFirstFourDays ) = 2 Then
intWeek = 1
Else
intWeek = DatePart("ww", dtDate, vbMonday, vbFirstFourDays )
End If
intDay = Weekday(dtDate, vbMonday)
intDayOfYear = DatePart("y", dtDate, vbMonday, vbFirstFourDays )
Select Case intDayOfYear
Case Is < 4
If intDay > 4 Then intYear = intYear - 1
Case Is > 362
If intDay < 4 Then intYear = intYear + 1
End Select
strRslt = CStr(intYear) & right$("0" & intWeek, 2) &
right$(Str$(int Day), 1)
End If
procexit:
On Error Resume Next
getISODate = strRslt
Exit Function
procerr:
MsgBox Err.Description
Resume procexit
End Function

Public Function getISOWk(mydate As Variant) As String
getISOWk = Mid(getISODate( mydate), 5, 2)
End Function

Clive
"Wayne Gillespie" <be*****@NObest fitsoftwareSPAM .com.au> wrote in message
news:3s******** *************** *********@4ax.c om...
On 6 Mar 2004 13:48:07 GMT, Lyle Fairfield <Mi************ @Invalid.Com> wrote:
pd******@steel case.com (PamelaDV) wrote in news:b6783f18.0 403041220.39301 038@posting.googl e.com:
Also is there a way to group dates by week? I have a user who wants a
report to group by week. I know I could create a table and assign
dates to a week, but I'm wondering if anyone has anything out there
already done that may be a little bit simpler.
An expression like

DatePart("ww ", vDate, vbSunday, vbFirstJan1)

can return a week of the year.

The enumerators vbSunday, vbFirstJan1 can be manipulated to modify the
results in keeping with your local practice.

Q200299 BUG: Format or DatePart Functions Can Return Wrong Week Number for

Last Monday in Year
The article includes a function which returns the correct weeknumber to the ISO standard.

Wayne Gillespie
Gosford NSW Australia

Nov 12 '05 #9
Wayne Gillespie <be*****@NObest fitsoftwareSPAM .com.au> wrote in
news:3s******** *************** *********@4ax.c om:
On 6 Mar 2004 13:48:07 GMT, Lyle Fairfield <Mi************ @Invalid.Com>
wrote:
pd******@stee lcase.com (PamelaDV) wrote in
news:b6783f18 .0403041220.393 01038 @posting.google .com:
Also is there a way to group dates by week? I have a user who wants a
report to group by week. I know I could create a table and assign
dates to a week, but I'm wondering if anyone has anything out there
already done that may be a little bit simpler.


An expression like

DatePart("ww" , vDate, vbSunday, vbFirstJan1)

can return a week of the year.

The enumerators vbSunday, vbFirstJan1 can be manipulated to modify the
results in keeping with your local practice.

Q200299 BUG: Format or DatePart Functions Can Return Wrong Week Number
for Last Monday in Year

The article includes a function which returns the correct weeknumber to
the ISO standard.


Thank you for drawing this to my attention.

Is any error returned for
DatePart("ww", vDate, vbSunday, vbFirstJan1)?

Does the error occur only for
DatePart("ww", vDate, vbMonday, vbFirstFourDays )?
[that is for calculating the ISO 8601 standard week number?]

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #10

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

Similar topics

5
2244
by: Hennie de Nooijer | last post by:
Hi, This is a diffcult issue to explain. I hope to make my problem clear to you. SITUATION I'm building A SLA Query for a customer. This customer has an awkward way to determine the SLA results ;-) Depending on a category which is stored in a headertable (Requests) a field and logic is determined how to get a proper Close_Date. This Close_date can be the closedate of the request. It is also possible that the close_date is a certain...
7
15149
by: Shuffs | last post by:
Could someone, anyone please tell me what I need to amend, to get this function to take Sunday as the first day of the week? I amended the Weekday parts to vbSunday (in my code, not the code attached), yet when I ran it for 28/09/2003 (UK date format) it returned Week 39. I would have expected it to return Week 40. However, I'm really stuck and my head is busting over this, so any pointers would be gratefully appreciated. Many thanks...
14
5108
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 DateAdd("d", 6, DateAdd("d", -weekday()+2,)))
4
2561
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 Access and our warehouse week runs from Sat to Fri. This is making my "week to date" calculations a day out. Is there a way that I can specify which day a new week starts on within this query???? Many thanks in advance,
9
3420
by: Ray | last post by:
I need to convert the normal calendar to show the week no., the period no. and the financial year. The financial year format is as follows:- Date start: 2 May, 2005 7 days a week, 4 weeks a period and 13 periods a year. normally 52 weeks per year but one 53-week a year every 6 years. The 53th week is included in period 13. Can someone advise any idea how to construct such conversion.
0
2864
by: Lee Harr | last post by:
I wrote a function to return the first date of a given week (and a few related functions) : -- return the first date in the given week CREATE or REPLACE FUNCTION week_start(integer, integer) RETURNS date AS ' DECLARE pyear ALIAS FOR $1; pweek ALIAS FOR $2;
6
14368
by: Jana | last post by:
Greetings Access Gurus! I am working on an app to send batch transactions to our bank, and the bank requires that we place an effective date on our files that is 'one business day in the future, excluding holidays and weekends.' I didn't want to build a table of holidays that would have to be continuously updated, so I searched high and low for a function that would tell me whether a given date was a holiday, to no avail. I did find an...
3
2623
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 recruiting calls per week, and so many of them have to result in at least an appointment. However, the "week" is Wednesday, 12:01pm to the following Wednesday, 12:00noon. So here are my questions... 1) Is there a way to change the standard week...
3
8281
by: Keo Sophon | last post by:
Fredrik Lundh wrote: Hi, I've tried calendar.month_name, it displays empty string, while calendar.month_name is "January"? Why does calendar.month_name's index not start with index 0 as calendar.day_name? Thanks, Sophon
0
9562
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9386
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8255
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.