Get Start date of Week number and Year

I’d like to build the following expression in my query
GetStartWeekNumber(DatePart("ww",[EnteredDate]), Year([EnteredDate]))
So if EnteredDate = 11/3/2009 the function would return 11/1/2009

But GetStartWeekNumber does not exist as an Access Built-In Function.
Is there another way to do this as an expression in a query?
I’m not familiar with creating my own functions.

Thanks.
0
Utf
11/16/2009 5:15:03 PM
access 16762 articles. 2 followers. Follow

10 Replies
1152 Views

Similar Articles

[PageSpeed] 8

That would depend on how you define the start of the week...

One option would be to get the day-of-week number of the date (in my 
system/setup, Monday is day 2), then subtract one less than that from the 
date to get the date on the start of THAT week.

Yes, you can do that in a query expression.

Regards

Jeff Boyce
Microsoft Access MVP

-- 
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

"h2fcell" <h2fcell@discussions.microsoft.com> wrote in message 
news:F1313536-3DC9-43CC-AC64-A881338EF12F@microsoft.com...
> I'd like to build the following expression in my query
> GetStartWeekNumber(DatePart("ww",[EnteredDate]), Year([EnteredDate]))
> So if EnteredDate = 11/3/2009 the function would return 11/1/2009
>
> But GetStartWeekNumber does not exist as an Access Built-In Function.
> Is there another way to do this as an expression in a query?
> I'm not familiar with creating my own functions.
>
> Thanks. 


0
Jeff
11/16/2009 5:41:56 PM
I think this will help:
Weekday(date, [firstdayofweek])
Returns a Variant (Integer) containing a whole number representing the day
of the week.
To get Sunday to be the first day of the week enter 1 for firstdayofweek OR
the constant vbSunday

for the date 3rd nov 2009 this returns 3 So you know Sundays 3 days back
from the date you entered

so then use dateAdd to get the date three days back and return it from the
function

Jim


"h2fcell" <h2fcell@discussions.microsoft.com> wrote in message 
news:F1313536-3DC9-43CC-AC64-A881338EF12F@microsoft.com...
> I'd like to build the following expression in my query
> GetStartWeekNumber(DatePart("ww",[EnteredDate]), Year([EnteredDate]))
> So if EnteredDate = 11/3/2009 the function would return 11/1/2009
>
> But GetStartWeekNumber does not exist as an Access Built-In Function.
> Is there another way to do this as an expression in a query?
> I'm not familiar with creating my own functions.
>
> Thanks. 


0
Jim
11/16/2009 5:46:52 PM
H2fcell -

Try this:

=DateAdd("d",-DatePart("w",[EnteredDate])+1,[EnteredDate])

This will check the day of the week (1 = Sunday) and subtract the number of 
days less one from the EnteredDate.  So if the current day of the week is 
Tuesday (DatePart will return 3), we subtract 2 days from the entered date.

-- 
Daryl S


"h2fcell" wrote:

> I’d like to build the following expression in my query
> GetStartWeekNumber(DatePart("ww",[EnteredDate]), Year([EnteredDate]))
> So if EnteredDate = 11/3/2009 the function would return 11/1/2009
> 
> But GetStartWeekNumber does not exist as an Access Built-In Function.
> Is there another way to do this as an expression in a query?
> I’m not familiar with creating my own functions.
> 
> Thanks.
0
Utf
11/17/2009 5:21:07 AM
FirstDayWeek: [EnteredDate] - Weekday([EnteredDate]) +1

The above assumes that you want Sunday to be the first day of the week.
-- 
Jerry Whittle, Microsoft Access MVP 
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"h2fcell" wrote:

> I’d like to build the following expression in my query
> GetStartWeekNumber(DatePart("ww",[EnteredDate]), Year([EnteredDate]))
> So if EnteredDate = 11/3/2009 the function would return 11/1/2009
> 
> But GetStartWeekNumber does not exist as an Access Built-In Function.
> Is there another way to do this as an expression in a query?
> I’m not familiar with creating my own functions.
> 
> Thanks.
0
Utf
11/17/2009 5:23:01 AM
Try this --
DateAdd("d",-Weekday([EnteredDate])+1,[EnteredDate])

-- 
Build a little, test a little.


"h2fcell" wrote:

> I’d like to build the following expression in my query
> GetStartWeekNumber(DatePart("ww",[EnteredDate]), Year([EnteredDate]))
> So if EnteredDate = 11/3/2009 the function would return 11/1/2009
> 
> But GetStartWeekNumber does not exist as an Access Built-In Function.
> Is there another way to do this as an expression in a query?
> I’m not familiar with creating my own functions.
> 
> Thanks.
0
Utf
11/17/2009 5:29:03 AM
Seems that my first reply didn't make it.

FirstDayOfWeek: [EnteredDate] - Weekday([EnteredDate]) +1

The above will work in a query. It assumes that Sunday is the first day of 
the week.
-- 
Jerry Whittle, Microsoft Access MVP 
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.

"h2fcell" wrote:

> I’d like to build the following expression in my query
> GetStartWeekNumber(DatePart("ww",[EnteredDate]), Year([EnteredDate]))
> So if EnteredDate = 11/3/2009 the function would return 11/1/2009
> 
> But GetStartWeekNumber does not exist as an Access Built-In Function.
> Is there another way to do this as an expression in a query?
> I’m not familiar with creating my own functions.
> 
> Thanks.
0
Utf
11/17/2009 5:32:02 AM
Try this:

    [Entered Date] + 1 - Weekday([Entered Date])

Weekday returns 1 for Sunday up to 7 for Saturday, and when you add or 
subtract integers to and from dates, the integers count as days forward or 
backward.

-- 
* Please click Yes if this was helpful *
Andy Smith
Senior Systems Analyst
Standard & Poor''s, NYC



"h2fcell" wrote:

> I’d like to build the following expression in my query
> GetStartWeekNumber(DatePart("ww",[EnteredDate]), Year([EnteredDate]))
> So if EnteredDate = 11/3/2009 the function would return 11/1/2009
> 
> But GetStartWeekNumber does not exist as an Access Built-In Function.
> Is there another way to do this as an expression in a query?
> I’m not familiar with creating my own functions.
> 
> Thanks.
0
Utf
11/17/2009 5:36:19 AM
DateAdd("d",-(Weekday([Some Date])-1),[Some Date])

will give the previous sunday of any date


-- 
Wayne
Manchester, England.



"h2fcell" wrote:

> I’d like to build the following expression in my query
> GetStartWeekNumber(DatePart("ww",[EnteredDate]), Year([EnteredDate]))
> So if EnteredDate = 11/3/2009 the function would return 11/1/2009
> 
> But GetStartWeekNumber does not exist as an Access Built-In Function.
> Is there another way to do this as an expression in a query?
> I’m not familiar with creating my own functions.
> 
> Thanks.
0
Utf
11/17/2009 5:38:01 AM
Here is a procedure that will calculate the first day of the week for the 
given date.  Copy and paste it into a module and then you can call it in your 
forms, report, queries.

'---------------------------------------------------------------------------------------
' Procedure : GetFirstofWeek
' Author    : CARDA Consultants Inc.
' Website   : http://www.cardaconsultants.com
' Purpose   : Determine the date of the first day of the week for a given date
' Copyright : The following may be altered and reused as you wish so long as 
the
'             copyright notice is left unchanged (including Author, Website 
and
'             Copyright).  It may not be sold/resold or reposted on other 
sites (links
'             back to this site are allowed).
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' dtDate    : Date to find the start of the week of
'
' Usage Example:
' ~~~~~~~~~~~~~~~~
' GetFirstofWeek(#10/2/2009#)
'
' Revision History:
' Rev       Date(yyyy/mm/dd)        Description
' 
**************************************************************************************
' 1         2009-Nov-16                 Initial Release
'---------------------------------------------------------------------------------------
Function GetFirstofWeek(dtDate As Date)
On Error GoTo Error_Handler
    'GetFirstofWeek = DateAdd("d", dtDate, -(Weekday(dtDate)) + 1) 'Returns 
the Sunday
    GetFirstofWeek = DateAdd("d", dtDate, -(Weekday(dtDate)) + 2) 'Returns 
the Monday

Exit Function

Error_Handler:
    MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf & 
"Error Number: " & _
    Err.Number & vbCrLf & "Error Source: GetFirstofWeek" & vbCrLf & "Error 
Description: " & _
    Err.Description, vbCritical, "An Error has Occured!"
    Exit Function
End Function
-- 
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"h2fcell" wrote:

> I’d like to build the following expression in my query
> GetStartWeekNumber(DatePart("ww",[EnteredDate]), Year([EnteredDate]))
> So if EnteredDate = 11/3/2009 the function would return 11/1/2009
> 
> But GetStartWeekNumber does not exist as an Access Built-In Function.
> Is there another way to do this as an expression in a query?
> I’m not familiar with creating my own functions.
> 
> Thanks.
0
Utf
11/17/2009 6:09:02 AM
All I can say is WOW! This date math is simple yet elegant.
Thank you very much.  This is what I was looking for.


"Andy Smith" wrote:

> 
> Try this:
> 
>     [Entered Date] + 1 - Weekday([Entered Date])
> 
> Weekday returns 1 for Sunday up to 7 for Saturday, and when you add or 
> subtract integers to and from dates, the integers count as days forward or 
> backward.
> 
> -- 
> * Please click Yes if this was helpful *
> Andy Smith
> Senior Systems Analyst
> Standard & Poor''s, NYC
> 
> 
> 
> "h2fcell" wrote:
> 
> > I’d like to build the following expression in my query
> > GetStartWeekNumber(DatePart("ww",[EnteredDate]), Year([EnteredDate]))
> > So if EnteredDate = 11/3/2009 the function would return 11/1/2009
> > 
> > But GetStartWeekNumber does not exist as an Access Built-In Function.
> > Is there another way to do this as an expression in a query?
> > I’m not familiar with creating my own functions.
> > 
> > Thanks.
0
Utf
11/17/2009 2:03:01 PM
Reply:

Similar Artilces:

year formula 04-13-10
I'm sure this is very simple, but for some reason it's not working for me. I have a log of training sessions provided to clients. I want to run a pivot table that totals the number of hours for the year. I track the date in the spreadsheet, so I wanted to add a column of "year" so that I can easily get totals per year. I want to reference the date column to populate the year for that date (I have hundreds of lines already so I don't want to do it manually) When i added the column & used the year function, it comes up with 1905 each time instead of...

Number format issue Access 2007
Access 2007. I've created a database with a number input and I'm getting the following errors. I've formatted a field as Number Field Size: Single Format: Currency Decimal Places: 0 I'm getting the following results Input 2,065,000,000 but it's rounding it to 2,064,999,936 Input 2,682,000,000 but getting rounded to 2,681,999,872 Any ideas on the reason for this? Do I have that field formatted properly? You help is GREATLY appreciated! (B^>)-]=[ Single is a floating point type. Accuracy is only 7 or 8 significant digits. More info: ...

i get error 404 not found when trying to download
I'm trying to download nokia pc suite to windows xp to upload gallery onto the computer but get error message404 not found - how can i download this pc suite please -- Krysy Albutt Krysy Albutt wrote: > I'm trying to download nokia pc suite to windows xp to upload gallery > onto the computer but get error message404 not found - how can i > download this pc suite please Care to enlighten us how this pertains to: - 1) Microsoft 2) Publisher 3) Windows If you're having problems downloading from the *NOKIA* site where do you think you should be directing your ...

How to get Calendar to send me reminders
I have changed my e-mail address but for some reason I cannot get Calendar to send reminders to my new address - I think I have carried out all that is necessary to effect the changover but I am not getting reminders sent. Can anyone help please? Is the Calendar Live ID based and accessible at Calendar.live.com ? -- ....winston ms-mvp mail "Dabardevon" wrote in message = news:FDC2B3B2-EDE4-41B1-BFC4-C0F9ED59CFB9@microsoft.com... I have changed my e-mail address but for some reason I cannot get = Calendar to send reminders to my new address - I think I have...

Some recipients get the attachment, some get winmail.dat
This one has me baffled. We are using Exchange 2000 and Outlook 2000 and have been for 8 months. No previous problems with attachments (.doc, .xls, .jpg). About 2 weeks ago, we started hearing from certain recipients that the attachment wasn't arriving; instead they were getting an unreadable file called winmail.dat. MS says that this is because the sender is using Rich Text to format the email. We have changed the senders to use Plain Text and still have the same problem. If the email is sent to several recipients, some will get the attachment fine, some will not. This didn'...

need a date look here
This is a multi-part message in MIME format --=_NextPart_2rfkindysadvnqw3nerasdf Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Get all the hots girls @ www.pearlymae.com --=_NextPart_2rfkindysadvnqw3nerasdf Content-Type: text/html Content-Transfer-Encoding: quoted-printable <html> <head> <meta name=3D"GENERATOR" content=3D"Microsoft FrontPage 6.0"> <meta name=3D"ProgId" content=3D"FrontPage.Editor.Document"> <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dwindow...

Automatic Numbering Rows
Hi all... Can't find how do to this using Excel 2003... I want to be able to have Excel automatically number rows (in the first column) that have text on them...but skip numbering rows without...and adjust the numbering if new rows get added in later. (I guess something similar to Bullets and Numbering in Word). Here's an example of what I want if I'm not making myself clear... 1. Text Here 2. Text Here 3. Text Here (Empty row...no text) 4. Text Here 5. Text Here (Empty row...no text) 6. Text Here etc.. Then...let's say...at a later date...I inserted a new row under...

wrong number in cell
In XP PRO & Excel 2002 I have a cell formated as General and unlocked. I try to enter a number { 08607100 } I hit enter and it changes to { 8607100 } no matter what I try it. This is another example of a problem in a cell I enter { 03E2 } hit enter and it changes to { 3.00E+02 }. Is there some bug in certain cells or with excel 2002 or is there some setting I am missing? Help -- Thanks MK pipco wrote: > In XP PRO & Excel 2002 I have a cell formated as General and unlocked. I > try to enter a number { 08607100 } I hit enter and it changes to { 8607100 &g...

How to get the CScrollBar's Handle in CTreeCtrl?
Hey,All: I thought I have a problem when I trid to get the CScrollBar's handle from my CTreeCtrl extended handle. Can anybody tell me whether I can get the handle of the CScrollBar from the CTreeCtrl? Thanks in advance! Carl :-| Carl wrote: > Hey,All: > > I thought I have a problem when I trid to get the CScrollBar's handle from > my CTreeCtrl extended handle. > Can anybody tell me whether I can get the handle of the CScrollBar from the > CTreeCtrl? > > Thanks in advance! > Carl > :-| > > Sorry, it is not that simple. The scroll bars that...

numbering multilevel list word 2007
trying to use a multilevel number list and when I hit ENTER (return) the numbering stops (the icon for numbering become un-highlighted) If this is numbering attached to headings, note that, by default, the Normal style will be applied to text when you press Enter (at the end of a heading). You can change the "Style for following paragraph" in the style definition for the relevant heading(s). -- Stefan Blom Microsoft Word MVP "dheuermann" <dheuermann@discussions.microsoft.com> wrote in message news:EEF7E0F7-76A1-4B55-98B3-981E303C7A68@microsoft.co...

formattting numbers
I am trying to format text in a textbox so it is in 3 columns (I'm using a fixed width font so it will align correctly). The 3rd column is a number. I would like it to be decimal point aligned (with possibly 1 leading zero - not 2 or 3 leading zeros). So I would like the output to be: AAAAA BBBBBBB 123.45 AAA BBBBB 0.11 AAAAA BBBBBBB 3.20 The code below aligns correctly but gives me 2 extra leading zeros. I basically want this output but have the 2 leading digits replaced with a space if no digit is present. Text1.SelText = " &quo...

A Crystal Beginner
I am using Crystal 9.2.4.77 and have loaded the Crystal enhancements. Now I want to do against the CRM database. What do I do? I thought I would create a data source to the CRM SQLserver, which I did, then connect to it through Crystal Reports. That works, but when I drill down on the AAA_MSCRM database to choose my tables, it shows me dbo as the only option (where did this come from??) and under that are just a few generic tables. No CRM tables. Something's not quite right. What am I missing? file - log on to aps server "KBLawson" <klawson@aetinc.com> wrote in ...

Matching number formats
I am using an INDEX/MATCH formula and do get a "VALUE NOT AVAILABLE" response. Both ranges have a "General" format. A [Copy][Paste Special][Formats] does not make the formats match. How can I make them respond to each other? On Thu, 12 May 2005 10:36:09 -0700, "raystub" <raystub@discussions.microsoft.com> wrote: >I am using an INDEX/MATCH formula and do get a "VALUE NOT AVAILABLE" >response. Both ranges have a "General" format. A [Copy][Paste >Special][Formats] does not make the formats match. How can I make them >resp...

Cannot get fast forward or fast reverse to work with WMP 11
I am running Vista Home Premium on a HP G 217-EM Notebook which comes pre-installed with Windows Media Player 11. When I play cds and try to fast forward or fast reverse by keeping the fast forward or fast reverse buttons constantly depressed nothing happens. Why is this, and can anyone come up with a solution? Many thanks This doesn't work on my system either, so it's probably just a limitation of WMP. Fast forward and fast reverse should work fine when you rip the CD's to MP3 or WMA files, and play these files instead. Regards -- Tim De Baets http://www....

Get paid while you get online!!
I found a great Internet company - Cashfiesta.com - that has created a product everyone can benefit from. They pay you while you work or play on your computer. All you need to do is keep their software - the FiestaBar=99 - active while you are online. They even pay you when your friends are using their computers. Unlike other companies, Cashfiesta gives you control over how much money you earn. They have an individual payrate based on the number of Special Offers you sign up for. As some of these offers are free, you can increase your payrate up to 33 times without spending a penny. It's...

EPays w/ Processing Date
I've been using MM for a number of years and have had relatively few problems...until now with MM05. I've searched this NG and FAQ web site but haven't found the issue/resolution. I have always had MM to record EPays with the PROCESSING DATE and have it checked in Settings/Online Services. MM05, however, records the transaction in the register with the SUBMITTING DATE. For example, yesterday I sent 2 payments to be paid on the 13th of the month but MM recorded yesterday's date NOT the payment date. That transaction, once submitted can't be changed as the check numbe...

Can't get auto-update (update) to install
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: Power PC I've been trying to manually check for updates to Word 2008, and I get a &quot;critical update&quot; notice, asking me to install auto-update. When I try to install it, I cannot. It just keeps repeating the attempt, in an &quot;endless loop.&quot; What to do? <br> Thank you. ...

Spreadsheet getting corrupted
Hello All: I have a relatively large spreadsheet. I am getting errors (see after my signature line). What could be causing these errors? Is it that the spreadsheet is too large? Thanks Deguza -------------------------------------------------------- Microsoft Office Excel File Repair Log Errors were detected in file 'C:\Documents and Settings\deguza\My Documents\sales\Sales_2006_2007.xls' The following is a list of repairs: Global PivotTable report information was repaired due to integrity problems. Global PivotTable report information was repaired due to integrity problems. Glo...

Increasing the number of files as recent files
Hello When I open file menu, I get the last 4 files I have previously openned. Is there a way to increase the number of recent files I have openned before? Thanks in advance. Hamed... Hi Hamed, You can go up to 9 entries in Excel 2000. Tools, Options, General, [x] recently used files list: -- 9 -- entries. --- HTH, David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001] My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm Search Page: http://www.mvps.org/dmcritchie/excel/search.htm "Hamed" <hamedarab@hotmail.com> wrote ... > When I op...

Reg getting the next IV Document Number field !
Hi, I am creating a window in dexterity similar to the item transaction entry window (Transactions>Inventory> Transaction Entry). In the Item transaction Entry window, the Document number field defaults to the next document number when we move the focus to that field. I wanted to know if there is any function , or table that i can access to get the next document number in the new window that i am creating. Thanks, swetha -- swetha >In the Item transaction Entry window, the Document number field defaults to the next document number when we move the focus to that field.< T...

Scaling XY charts with suppressed starting value
The autoscaling feature of the Excel graphing function seems to have (limited) mind of its own. I'm trying to graph Y-values in the -1.5 t 1.5 range and X-values from 190 to 410 with the minimum from 190 to 29 and the max value from 290 to 410. The autoscaling of Y works fine, but the X-axis always start at 0 while the high value properly sets the maximum. Of course, I could fi the minimum at 190, but that is not what I had in mind. Does anyone know how to overcome this limitation without using a macro -- Message posted from http://www.ExcelForum.com Per - You need to make an XY Sca...

How do I get??
Sorry if this seems a fairly easy question to you guys. I have a spreadsheet and I need to get the current system time into a cell. The format of the time is hh:mm am/pm. Any assistance would be most helpful. Hi try =INT(NOW()) in this cell and format is to your needs -- Regards Frank Kabel Frankfurt, Germany PM wrote: > Sorry if this seems a fairly easy question to you guys. > > I have a spreadsheet and I need to get the current system time into a > cell. The format of the time is hh:mm am/pm. > > Any assistance would be most helpful. PM, in the cell you want pu...

Get notified when Out of Office is on
I am using Outlook 2007. With 2003, when returning from leave, I used to get a notification that the Outlook out of office was still on and asking me if I wanted to switch it off. This reminder no longer appears with 2007. How can I switch this setting on so that I get the notification? "Mary Ann" <MaryAnn@discussions.microsoft.com> wrote in message news:ED5533A7-D0EA-41B8-B1A0-A9D15FB6FD98@microsoft.com... >I am using Outlook 2007. With 2003, when returning from leave, I used to get > a notification that the Outlook out of office was still on and asking me ...

Getting Control ID in Active X control
GetWindowLong return 0. You need to call GetDlgCtrlID from outside the activex control as the function available within the control returns an arbitrary value of zero. Take a look at this article http://xendra.ens.uabc.mx/~sinfante/loo/libro/ch17_4.htm particularly the paragraph preceeding the title "MFC and Ambient Properties". This really begs the question why you want the ID in the first place as activex controls have to be fully self containing to operate - with a few exceptions where sibling controls need to be able to locate each other. - Tim "ytv" <...

over VPN, it gets stuck when sending outgoing email
When I use VPN to connect to work from home, the outlook can not finish sending outgoing emails. The progress bar moves to the end but then stops there forever. It can never finish. The receiving of new incoming emails work fine. All other network functionality works, e.g. internet browsing, telnet, ftp, etc, all work fine. My system is win2k. I use linksys wireless DSL router. I'd appreciate any hint! Are you using Exchange server? I'd set up your mail profile to prompt you to work offline or online - when using VPN, work offline with scheduled syncs. If not using exchange, pos...