473,387 Members | 1,812 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,387 software developers and data experts.

Find The Week Begin and End Date Based On Current Date

I apologize in advance if this has been asked for or if I'm missing somithing obvious, but I have a form that I want to auto populate the week beginning and week ending date based on the current week. I'd also like to be able to selcect (via Option Group) last week and it give me the week begin and end date.

Thanks in advance.

Jeff
Aug 18 '10 #1
4 48363
to get you started, if Sunday is the first day of the week, here are formulae that can be used in queries or VBA or even as Default values in a form's text boxes, etc.

start of week = date()-weekday(date())+1
end of week = date()-weekday(date())+7

date() = today's date
weekday(date()) = the day of the week of today
Aug 18 '10 #2
Stupid question - this will give me the beginning of the the current week, but how do I get the previous week's beginning and end?
Aug 19 '10 #3
Stewart Ross
2,545 Expert Mod 2GB
To go back one week subtract 7 from the value returned. Using Manxman's post as an example:

start of last week = date()-weekday(date())-6
end of last week = date()-weekday(date())

Note that these refer to Sunday as the first day of the week. To make it Monday use an optional parameter in the Weekday function which has the value of 2 for Monday as the first day of the week:

start of week = date()-weekday(date(), 2)+1
end of week = date()-weekday(date(), 2)+7
start of last week = date()-weekday(date(), 2)-6
end of last week = date()-weekday(date(), 2)

-Stewart
Aug 19 '10 #4
Jeff

As Stewart pointed out, just subtract another 7 days for the beginning of the previous week.

We all start at the beginning. I always tell people there are no stupid questions when you are a beginner.

However, when you receive an answer, stop and try to analyze it. Do not blindly copy it. Figure it out. If you do, your knowledge will grow faster.

Why does "start_of_week = date()-weekday(date())+1" work?

If you understand why, you will start to answer your own questions. If you do not understand why, ask us. If you do not ask, you will have to keep asking us for help, long after you should.

If it is VBA code, use Ctrl-G to enter it in and play with it to see what changes do.

Inside Access, press the Ctrl-G combo. A special screen opens. Type the following and press enter.

? date()-weekday(date())+1

What happens?

Play, and you will learn fast.
Aug 19 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Matt | last post by:
My ASP page allows the user select the date, and it will display the report during that week of that date. My question is when the program query database, I need to know the beginning date and...
2
by: AdityaK | last post by:
Is there anyway I can get weekend date for a given date using DB2 query? I couldn't find any DB2 function that can be used to do so. Thanks, Aditya
1
by: ToysNTreasures | last post by:
Hi, I'm working on a class project in which I have to create a simple hotel reservation database using Access. I've created a couple of tables and queries that allow a user to determine room...
1
by: ET | last post by:
Please help with the query: There are two tables, A and B. A table has information about cell phones, like cell number, sim number, model, manufacturer etc... B table has user related...
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
5
by: bruce24444 | last post by:
I have a database which assigns warranty claims to people with a main screen showing number of files assigned to each person. The number assigned shows day, week, month and year numbers so they can...
1
by: ananthaT | last post by:
Hi all, How can we delete files based on time in java. i am trying to use if(!FileUtils.isFileOlder(file,date)) //here date is current date if(file.delete()) ...
1
by: tmcjunkin | last post by:
I'm trying to back into this project by defining what the user needs to see when they open a form. I'm between beginner and intermediate with vba, but have been using access for years. When the...
6
vikas1111
by: vikas1111 | last post by:
How to set date to current date...it should automatically update..
3
by: testperl | last post by:
Can anyone help me to make a perl script that could delete 1 week old files based on the date created? I made a folder: (August 16, 2008 to September 1, 2008) 08-16-08 08-17-08 08-18-08...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.