473,695 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

the penultimate week and last week of data for each month

I would like to return data from the last 2 weeks of each given month
in Javascript, but in 2 formats.

So, the penultimate week (Monday to Sunday) and the last week (Monday
to ??)

I'm not sure if it can be done, but all help welcomed.

E.g. I have December and would like to see the last 2 weeks.. So this
doesnt mean the last 15 days. What i mean by this is...

Sometimes a Week will cross over into 2 months, where it finishes on
Tuesday and starts on Wednesday, like November 2004 for example.

With the November 2004 example, means there are 5 weeks in November..
so i would like to see the data within the 4th week (Monday to Sunday)
and the 5th week (Monday to Tuesday). Of course for every month of the
year.
Is this possible??

I look forward to hearing your thoughts.
SimonC

Jul 23 '05 #1
13 3605
"SimonC" <si******@yahoo .co.uk> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I would like to return data from the last 2 weeks of each given month
in Javascript, but in 2 formats.

So, the penultimate week (Monday to Sunday) and the last week (Monday
to ??)

I'm not sure if it can be done, but all help welcomed.

E.g. I have December and would like to see the last 2 weeks.. So this
doesnt mean the last 15 days. What i mean by this is...

Sometimes a Week will cross over into 2 months, where it finishes on
Tuesday and starts on Wednesday, like November 2004 for example.

With the November 2004 example, means there are 5 weeks in November..
so i would like to see the data within the 4th week (Monday to Sunday)
and the 5th week (Monday to Tuesday). Of course for every month of the
year.
Is this possible??

I look forward to hearing your thoughts.
SimonC


Will this help? Watch for word-wrap.

Option Explicit
'*
'* Declare Constants
'*
Const cVBS = "penuweek.v bs"
Const cYER = 2004
'*
'* Declare Variables
'*
Dim arrDAT(12,1)
Dim intDAT
Dim strDAT
Dim intDOW
Dim intMON
Dim strYER
strYER = cYER
'*
'* 12 Months
'*
For intMON = 1 To 12
'*
'* First day of next month
'*
strDAT = DateSerial(strY ER,intMON+1,1)
'*
'* Last day of this month
'*
strDAT = DateAdd("d",-1,strDAT)
'*
'* Day of week
'*
intDOW = DatePart("w",st rDAT,2)
'*
'* Date of Monday before last
'*
If intDOW = 1 Then intDOW = 8
intDAT = (intDOW + 6) * -1
strDAT = DateAdd("d",int DAT,strDAT)
arrDAT(intMON,0 ) = strDAT
'*
'* Date of Sunday two weeks later
'*
strDAT = DateAdd("d",13, strDAT)
arrDAT(intMON,1 ) = strDAT
Next
'*
'* Results
'*
strDAT = ""
For intMON = 1 To 12
strDAT = strDAT & intMON & ". "
strDAT = strDAT & arrDAT(intMON,0 ) & " : "
strDAT = strDAT & arrDAT(intMON,1 ) & vbCrLf
Next
MsgBox strDAT,vbInform ation,cVBS
Jul 23 '05 #2
McKirahan wrote:
"SimonC" <si******@yahoo .co.uk> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I would like to return data from the last 2 weeks of each given month
in Javascript, but in 2 formats.
[...]
Will this help? Watch for word-wrap.

Since this is a JavaScript forum, and the OP has explicitly asked for
JavaScript, why would 'this' help?
Option Explicit
'*
'* Declare Constants

[...]

Perhaps if you re-write it in an appropriate language...

--
Zif
Jul 23 '05 #3
"Zifud" <zi***@hotmail. com.com> wrote in message
news:41******** **************@ per-qv1-newsreader-01.iinet.net.au ...
McKirahan wrote:
"SimonC" <si******@yahoo .co.uk> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I would like to return data from the last 2 weeks of each given month
in Javascript, but in 2 formats.

[...]

Will this help? Watch for word-wrap.


Since this is a JavaScript forum, and the OP has explicitly asked for
JavaScript, why would 'this' help?
Option Explicit
'*
'* Declare Constants

[...]

Perhaps if you re-write it in an appropriate language...

--
Zif


The OP did ask "Is this possible??" -- "this" (at least) shows that it is...
You're right, of course. I post to multiple groups and sometimes when I
think of a solution I forget to customize it to the group.
Jul 23 '05 #4
SimonC wrote:
I would like to return data from the last 2 weeks of each given month
in Javascript, but in 2 formats.

So, the penultimate week (Monday to Sunday) and the last week (Monday
to ??)

I'm not sure if it can be done, but all help welcomed.

E.g. I have December and would like to see the last 2 weeks.. So this
doesnt mean the last 15 days. What i mean by this is...

Sometimes a Week will cross over into 2 months, where it finishes on
Tuesday and starts on Wednesday, like November 2004 for example.

With the November 2004 example, means there are 5 weeks in November..
so i would like to see the data within the 4th week (Monday to Sunday)
and the 5th week (Monday to Tuesday). Of course for every month of the
year.
Is this possible??

I look forward to hearing your thoughts.
SimonC


days=["Sun","Mon","Tu e","Wed","Thu", "Fri","Sat"];

// Find the Nth day(Three character string,
// e.g "Thu", or use index [Sun=0, Sat=6])
// of the month (full) of a given year (full)
// To find the first Sunday of April 2004:
// var spring = getNthDayInMont h(1,"Sun","Apri l",2004)
// or spring = getNthDayInMont h(1,0,"April",2 004)
// returns "4" (April 4th)
function getNthDayInMont h(N,day,month,y ear){
day=(getIndex(d ay,days)>-1)? getIndex(day,da ys):day;
b=getMonthLengt h(month,year);
d=7*N - 6 + (7+day-getFirstDayOfMo nth(month,year) )%7
return d<b? d:"error";
}
See http://mickweb.com/javascript/dates/dateFunctions.html for
supporting functions
Mick
Jul 23 '05 #5
JRS: In article <11************ **********@z14g 2000cwz.googleg roups.com>
, dated Fri, 31 Dec 2004 03:04:46, seen in news:comp.lang. javascript,
SimonC <si******@yahoo .co.uk> posted :
I would like to return data from the last 2 weeks of each given month
in Javascript, but in 2 formats.
Firstly, beware of American solutions; they have funny ideas about dates
over there, and theirs may not be what you want.
FYI, ISO 8601:2000 weeks are ALWAYS Mon=1 to Sun=7. ISO 8601:2000 does
not define week-of-month (ISO 8601:2004 might, though); but there is an
obvious definition by analogy with week-of-year; a week belongs to that
Calendar Month in which its Thursday lies.

So, the penultimate week (Monday to Sunday) and the last week (Monday
to ??)

I'm not sure if it can be done, but all help welcomed.

E.g. I have December and would like to see the last 2 weeks.. So this
doesnt mean the last 15 days. What i mean by this is...

Sometimes a Week will cross over into 2 months, where it finishes on
Tuesday and starts on Wednesday, like November 2004 for example.

With the November 2004 example, means there are 5 weeks in November..
so i would like to see the data within the 4th week (Monday to Sunday)
and the 5th week (Monday to Tuesday). Of course for every month of the
year.
If the last week ends on the last day of the month, and that is not
Sunday, then are you happy about having days in the following month
before the Monday that starts its first full week?

Is this possible??


Yes, but one must first understand it, and maybe believe it.
AFAICS, your last week starts on the last Monday of the month, which is
easily calculated as the zeroth Monday of the following month, or as
0..6 days before the zeroth of that month; and the previous week starts
7 days earlier.

I think the following fits the case; it will show the desired interval
for the first to the 20th months of 2004. Adapt to suit. Test.

for (j=1; j<20; j++) {
X = new Date(2004, j, 0) ; D = new Date(+X) // D is a copy of X
W = D.getDay() // 0..6 Sun-Sat
D.setDate(D.get Date() - (W+6)%7 - 7) // back 0..6 + 7 days
document.writel n(D, ' \t ', X, '<br>')
}

*** *** *** Read the newsgroup FAQ; see below.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #6
JRS: In article <rLbBd.593649$w V.485877@attbi_ s54>, dated Fri, 31 Dec
2004 12:38:47, seen in news:comp.lang. javascript, McKirahan
<Ne**@McKirahan .com> posted :
For intMON = 1 To 12
'*
'* First day of next month
'*
strDAT = DateSerial(strY ER,intMON+1,1)
'*
'* Last day of this month
'*
strDAT = DateAdd("d",-1,strDAT)

(a) For the second line, why not just strDat = strDat-1 ??

(b) For both, why not strDAT = DateSerial(strY ER, intMON+1, 0) ??
You should learn more about the languages that you use before you
presume to be able to write efficient algorithms; and you should note
that java != VB.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 23 '05 #7

Dr John Stockton wrote:
JRS: In article <rLbBd.593649$w V.485877@attbi_ s54>, dated Fri, 31 Dec 2004 12:38:47, seen in news:comp.lang. javascript, McKirahan
<Ne**@McKirahan .com> posted :
For intMON = 1 To 12
'*
'* First day of next month
'*
strDAT = DateSerial(strY ER,intMON+1,1)
'*
'* Last day of this month
'*
strDAT = DateAdd("d",-1,strDAT)

(a) For the second line, why not just strDat = strDat-1 ??

(b) For both, why not strDAT = DateSerial(strY ER, intMON+1, 0)

??

You should learn more about the languages that you use before you
presume to be able to write efficient algorithms; and you should note
that java != VB.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. © Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm

critdate.htm etc.

--------------------------------------------------------------------
Thanks guys for all the help. I am starting to understand some of it
more now. As you're probably aware, im no JavaScript expert... Quite
the opposite.

I have tried the scripts posted on here, but they're not quite working
in the way i would like.

I am actually trying to produce this data against a report that i have
written against a Database. The tool is called "Brio" (like Crystal
reports). So i have my columns of data. Now, the data i would like to
get is as described above, but against a column name (field) named as
"NoOfOrders " (this is a date field in the following format: 01/01/2004
00:00:00)

Just as an example of what i have already in the report in terms of
Javascript, below is a simple script i created.
--------
DayNo = new Date(NoOfOrders ); weekday=DayNo.g etDay()
--------

Again, all help on this would be great and thanks again for the current
input.

Cheers...
SimonC

Jul 23 '05 #8
JRS: In article <HB************ ********@twiste r.nyroc.rr.com> , dated
Fri, 31 Dec 2004 15:53:11, seen in news:comp.lang. javascript, Mick White
<mw***********@ rochester.rr.co m> posted :
days=["Sun","Mon","Tu e","Wed","Thu", "Fri","Sat"];

// Find the Nth day(Three character string,
// e.g "Thu", or use index [Sun=0, Sat=6])
// of the month (full) of a given year (full)
// To find the first Sunday of April 2004:
// var spring = getNthDayInMont h(1,"Sun","Apri l",2004)
// or spring = getNthDayInMont h(1,0,"April",2 004)
// returns "4" (April 4th)
function getNthDayInMont h(N,day,month,y ear){
day=(getIndex( day,days)>-1)? getIndex(day,da ys):day;
b=getMonthLeng th(month,year);
d=7*N - 6 + (7+day-getFirstDayOfMo nth(month,year) )%7
return d<b? d:"error";
}
See http://mickweb.com/javascript/dates/dateFunctions.html for
supporting functions

For any given month, there is a value of N, 4 or 5, that should select
the very last day; e.g. 2005-01-31 is the Fifth Monday of this month.
But I would expect your b=getMonthLengt h(month,year) to be 31 for this
month, which the code seems to show as giving an error message for d=31.
Have I misunderstood?

If a Date Object is to be generated from the result, ISTM easier and
safer to confirm that getMonth() is as it should be. For speed, you
could use something like
return ( d < 29 || d <= getMonthLength ) ? d : 0
so that the expensive getMonthLength is only called in a few cases.

In practice, the month-length can only matter for N=5; and, as the
outside world has spotted this, the 5th X-day is rarely called for,
except when specified to mean the last X-day. The latter can easily be
obtained as the zeroth X-day of the following month.

Your function, as shown, pollutes the namespace by stomping on the
previous value of globals b & d.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 23 '05 #9
JRS: In article <11************ *********@f14g2 000cwb.googlegr oups.com>,
dated Mon, 3 Jan 2005 00:56:27, seen in news:comp.lang. javascript,
SimonC <si******@yahoo .co.uk> posted :
Now, the data i would like to
get is as described above, but against a column name (field) named as
"NoOfOrders " (this is a date field in the following format: 01/01/2004
00:00:00)
Not a good example date. Better to choose a date after the 12th of its
month; your example is compatible with each of the customary UK & US
formats. Better still to use, say, 2004/01/17 or 2004-01-17.
Just as an example of what i have already in the report in terms of
Javascript, below is a simple script i created.
--------
DayNo = new Date(NoOfOrders ); weekday=DayNo.g etDay()
--------


If NoOfOrders means anything like Number of Orders, ISTM unlikely
(unless orders are received at exactly one per millisecond, starting at
1970-00-01 00:00:00.001 GMT) that it can be so converted to a reasonable
DayNo. Note that getDay returns 0..6; to get standard ISO/EU/UK day
numbering, that 0 must become a 7.

See below.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #10

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

Similar topics

2
5214
by: androtech | last post by:
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
2
2344
by: planetthoughtful | last post by:
Hi All, I'm building some reports in Acc97 and using a custom calendar form to allow users to pick dates with which to report. I'm wondering if there's an easy way in code to be able to automatically work out the end-of-week date and end-of-month date from an arbitrary date value? To explain a little further. Let's say a user wants to view a weekly
14
3492
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity. However, the expectation changes - it may be 60% for a while, then change to 50%. Initially, I was averaging the expectation, along with the productivity, but what I'm being asked is to look at the average productivity/performance compared to...
6
25363
by: aarklon | last post by:
Hi folks, I found an algorithm for calculating the day of the week here:- http://www.faqs.org/faqs/calendars/faq/part1/index.html in the section titled 2.5 what day of the week was 2 august 1953 I checked the algorithm it is very correct.
10
1251
by: Jim | last post by:
I'm sure this has been asked before but I can't find any postings. I have a table that has weekly inspections for multiple buildings. What I need to do is break these down by the week of the month of my choosing. Let me explain; I can get my week numbers no problem. I can get the date from the week numbers no problem. What I haven't been able to do is put things together and make a simple function that will allow my users to select from...
9
3672
by: AideenWolf | last post by:
Windows XP - Access 2003 I've been researching this for about 3 weeks now and I'm no closer then when I started so any help you all give me will save my hair. I'm VERY new and learning as I go so bare with me. What I want to do is generate a new record for each date an event is held on. The events are reoccuring events. Daily, weekly, etc. What I've done so far: I have a foum that the user enters the Start date and End Date.
2
3112
by: tasmontique | last post by:
I am working on an access 2002 flight schedule database. I am new to access but have some basic understanding of sql and vb6 code. I have learned a lot from this website. Thanks much Hopefully you can help me with this one. This database handles a varying number of flights for a varying number of days for a varying number of months. I have a number of tables as follows. I tried to normalize to the best of my ability.
5
2834
by: cssExp | last post by:
the problem is, i have a dynamic database driven site, each data is entered with year, week etc.. 2 months ago assuming I'll create sort option in future i put everything, i.e year, week, hour, minute etc.. but forgot month. Now i'm adding sort option but i need month but not available during database entry i use the following. $year = date('Y'); $week = date('W'); $day = date('d'); $hour = date('H'); $minute = date('i');.
1
2313
by: guyborn | last post by:
I have been trying to get data from the database from the of the previous month to the second last week of the current month.I only managed to get data from the previous month to today's date. your help will be highly appreciated Regards Guyborn
0
8998
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
8857
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
8831
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...
1
6494
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
4346
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4586
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3013
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
2
2278
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1979
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.