473,508 Members | 2,374 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I find the week ending date?

31 New Member
Hi All,

Edit:

I currently have table where I need to find the Week Ending date for a rolling 15 weeks, where each week is a separate column. It goes from Sched01 - Sched15.

The Sched01 column is always the current Week Ending Date (Saturday). However, if a month ends on any other day but Saturday then I need the month end date to be the Week Ending Date.

For example as of 7/22/2011:
Sched01 - Week Ending Date is currently 7/23/2011
Sched02 - Week Ending Date is currently 7/30/2011
Sched03 - Week Ending Date is currently 7/31/2011
Sched04 - Week Ending Date is currently 8/06/2011

For example as of 7/25/2011:
Sched01 - Week Ending Date is currently 7/30/2011
Sched02 - Week Ending Date is currently 7/31/2011
Sched03 - Week Ending Date is currently 8/06/2011
Sched04 - Week Ending Date is currently 8/13/2011

Any help is appreciated.
Jul 21 '11 #1
9 5286
Rabbit
12,516 Recognized Expert Moderator MVP
If you subtract the weekday number of the date from 7, and then add that many days to the date, that will give you the week ending date.

Then you check if that date is in the next month, if it is, you use the end of the month.
Jul 21 '11 #2
NeoPa
32,557 Recognized Expert Moderator MVP
What's in your table?

Always 15 records? A history including 15 for the upcoming weeks?

When are you requiring to show/use these values?

There are so many possible approaches to this, that without more info it's unprofitable trying to answer.
Jul 23 '11 #3
BarbQb
31 New Member
NeoPa-

The table contains product production by week.

One record is product X and the Production Amount in the following 42 weeks (columns Sched01-Sched42), but I am only interested in the first 15 weeks (columns Sched01-Sched15).

There is no history in the table. Sched01 is always the current Week Ending Date.

I would like to show everything that is being produced in each of the 15 weeks, but the problem is finding the dates for each week. The users will be checking this schedule 2-3 times per week.

Eventually I would like to join it with another table that shows the product that is coming in each week. I have already configured the dates for that table, but they are not set up the same way.

Please let me know if you need any more information.
Jul 23 '11 #4
NeoPa
32,557 Recognized Expert Moderator MVP
So I guess you have a form or report, or other similar object, where you wish to update the display for the column titles so that instead of showing just Sched01, Sched02, etc, it shows the W/E dates for each column. Is that right?

If so, what type of object are we dealing with? A form? A report?
Jul 23 '11 #5
BarbQb
31 New Member
Sorry about that.

I would like for the column titles to be the W/E date and not Sched01, 02,... I am just working with a query right now. Eventually I will put it into a report.
Jul 25 '11 #6
NeoPa
32,557 Recognized Expert Moderator MVP
Right. I think we need to get something clear here at this point :

Column titles in queries cannot be determined from within the query. Column titles can be assigned to a query, but not from within the query itself. The columns must be available and in the query (design) itself and are not dependent on, or ralative to, the data at any particular time of processing the query. Furthermore, even if it were possible to determine the column headings in this way for the query, it would make it impossible/insanely difficult to use that query for a report. It is possible to create the query (SQL) with your desired columns titles in VBA code on the fly. Because this would be unproductive though, as far as using in a report, I will ignore this for now.

All that said, you can only really benefit by determining the titles within the report itself (This would also be true for a Form if that were your requirement).

Before continuing I'd like you to confirm that you understand and accept what I've just said, and my proceeding along these lines will make sense. It does mean, of course, that your development of the query can go ahead without further delay as there is really no need at this point to worry about the titles (The controls in the eventual report will need to be bound to fields from the query with names that are known in advance. IE. The known ones of Sched01, Sched02, etc.).
Jul 25 '11 #7
BarbQb
31 New Member
Thanks NeoPa. I think I jumped ahead of myself when I said I wanted to change the column titles in the Query. I definitely had an idea in my head that will not be plausible.

But, I do understand and agree that it will be beneficial to figure out the Week Ending Dates within the report.
Jul 26 '11 #8
NeoPa
32,557 Recognized Expert Moderator MVP
I can't test this without your database but it should work hopefully (It compiles ok at least) :

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub Report_Open(Cancel As Integer)
  5.     Dim intSched As Integer, intMonth As Integer
  6.     Dim datNext As Date, datSat As Date
  7.  
  8.     datNext = Date
  9.     datSat = DateAdd("d", 7 - Weekday(datNext), datNext)
  10.     For intSched = 1 To 15
  11.         If Month(DateAdd("d", 1, datNext)) = Month(datSat) Then
  12.             datNext = datSat
  13.             datSat = DateAdd("d", 7, datSat)
  14.         Else
  15.             datNext = DateAdd("d", -1, CDate(Format(datSat, "m/yyyy")))
  16.         End If
  17.         With Me.Controls("txtSched" & Format(intSched, "00"))
  18.             .Caption = Format(datNext, "ddd d mmm yyyy")
  19.         End With
  20.     Next intSched
  21. End Sub
You can choose how you want the column titled by changing line #18.
Jul 27 '11 #9
BarbQb
31 New Member
Thank you very much, NeoPa. I will let you know how it works.
Aug 2 '11 #10

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

Similar topics

2
5857
by: David Olsen | last post by:
Would any of you kind souls now how to put into an unbound text box the week commencing date for the current week which you are in, so that the report heading would say something like for example,...
3
5923
by: Matt | last post by:
Given a date, how to find the beginning date and ending date of that week please advise!
4
2133
by: csgraham74 | last post by:
Hi Guys, I was wondering if anyone could help me find a function to get a week ending function?? i.e. week ending on sunday Therefore if a i was to input todays date in my function it would...
7
9027
by: derekdeben | last post by:
Hi, I have created a report that totals the number of days it took a product to ship by percentage by a date range for a specific location. My data comes from a query with the following headers: ...
2
1736
by: nex85 | last post by:
hi! HOUR FROM TIME i) does anyone know how to determine which hour a time value lies in? the arrival time is in hh:mm:ss format. for e.g.: for an arrival time of 17:00:26, the correct conversion...
1
5325
by: GoDogGo | last post by:
I need code to find next Tuesdays date. I have started with this: TuesdaysDate = DateAdd("d", vbTuesday - Weekday(Date), Date) However if today is Wednesday it returns yesterdays date. I...
3
2767
Inbaraj
by: Inbaraj | last post by:
Hi... I have a Table in that i have inserted the DATE as VARCHAR now in that i Want to get the Max Date. I am new to MySQL Plz help me how to find the max date. with regard Inbaraj.D
2
1155
by: juster21 | last post by:
I need to be able to have my application select the current week-ending date from a listbox. I have seen some things on the net but nothing that really helps. If anyone can provide help, that...
0
2056
by: jmarcrum | last post by:
Hi all, I have an excel spreadsheet that in column A, has a formula under the first row in A2 that automatically calculates the Week-ending date when someone starts typing something in cells B2,...
2
10257
akashazad
by: akashazad | last post by:
Dear Friends I would Like to know if there is any way we can find the Current Date format of the Server. I mean is there any Query or function by which we can find out the the Date format...
0
7224
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
7323
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
7380
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...
1
7039
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
7494
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...
0
5626
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,...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1553
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 ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.