By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,693 Members | 1,737 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,693 IT Pros & Developers. It's quick & easy.

Getdate() over-ride?

P: n/a
I'm trying to produce an array of working days but want to force
Saturday and Sunday to return the date of the previous Friday, e.g.
Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
9/11/04 should return Friday 9/10/04.

I've tried getdate()-1 and getdate()-2 respectively but am getting
stack overflow errors. Am I doing anything wrong, or is this just not
possible?

Jul 23 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
On Sun, 12 Sep 2004 21:29:15 GMT, Bill Edwards <bi**********@ntlworld.com>
wrote:
I'm trying to produce an array of working days but want to force
Saturday and Sunday to return the date of the previous Friday, e.g.
Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
9/11/04 should return Friday 9/10/04.

I've tried getdate()-1 and getdate()-2 respectively but am getting stack
overflow errors. Am I doing anything wrong, or is this just not possible?


Yes, it's possible, but how can we tell what you've done wrong? You
haven't shown any code.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2

P: n/a
Bill Edwards wrote on 12 sep 2004 in comp.lang.javascript:
I'm trying to produce an array of working days but want to force
Saturday and Sunday to return the date of the previous Friday, e.g.
Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
9/11/04 should return Friday 9/10/04.

I've tried getdate()-1 and getdate()-2 respectively but am getting
stack overflow errors. Am I doing anything wrong, or is this just not
possible?


anything is possible. Please show your code.

If not ("working days" is defined as mon..fri) please show your definition.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #3

P: n/a
Lee
Bill Edwards said:

I'm trying to produce an array of working days but want to force
Saturday and Sunday to return the date of the previous Friday, e.g.
Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
9/11/04 should return Friday 9/10/04.

I've tried getdate()-1 and getdate()-2 respectively but am getting
stack overflow errors. Am I doing anything wrong, or is this just not
possible?


Yes, you are doing something wrong, but I don't think any of us
can guess exactly what it is from that description. Post the URL
of a web page or s *brief* example that demonstrates the problem.

There is no "getdate()" method that I know of, so I assume you
really mean "getDate()".
What are you doing with the value after you subtract from it?
What will your code do on Saturday, January 1, 2005?

Jul 23 '05 #4

P: n/a
>On Sun, 12 Sep 2004 21:29:15 GMT, Bill Edwards <bi**********@ntlworld.com> wrote:

I'm trying to produce an array of working days but want to force
Saturday and Sunday to return the date of the previous Friday, e.g.
Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
9/11/04 should return Friday 9/10/04.

I've tried getdate()-1 and getdate()-2 respectively but am getting
stack overflow errors. Am I doing anything wrong, or is this just not
possible?


Do you mean something like this ASP code Bill?

Function LastBusinessDay(sDate)
Dim iDay, iDaysToAdd, iDate

iDaysToAdd = 0
iDate = sDate

x = 1

Do while iDaysToAdd >= 0
If Weekday(iDate) = 1 or Weekday(iDate) = 7 or _
isHoliday(iDate) <> 0 then
iDay = Weekday(iDate)
Select Case cint(iDay)
Case 1 'Sunday
iDate = DateAdd("d", -1, iDate)
Case 7 'Saturday
iDate = DateAdd("d", -1, iDate)
Case else 'this is a valid day
if isHoliday(iDate) > 0 then
iDate = dateadd("d", -(isHoliday(iDate)),
iDate)
else
iDaysToAdd = iDaysToAdd - 1
end if
End Select
end if
Loop

LastBusinessDay = iDate
End Function
Jul 23 '05 #5

P: n/a
>On Sun, 12 Sep 2004 21:29:15 GMT, Bill Edwards <bi**********@ntlworld.com> wrote:

I'm trying to produce an array of working days but want to force
Saturday and Sunday to return the date of the previous Friday, e.g.
Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
9/11/04 should return Friday 9/10/04.

I've tried getdate()-1 and getdate()-2 respectively but am getting
stack overflow errors. Am I doing anything wrong, or is this just not
possible?


Or something like this VB code?

Function LastBusDay(ByVal D As Date) As Date
Dim D2 As Variant
D2 = DateSerial(Year(D), Month(D) + 1, 0)
Do While Weekday(D2) = 1 Or Weekday(D2) = 7
D2 = D2 - 1
Loop
LastBusDay = D2
End Function

Jul 23 '05 #6

P: n/a
JRS: In article <im********************************@4ax.com>, dated
Mon, 13 Sep 2004 09:31:29, seen in news:comp.lang.javascript, Joseph
Numpty <jo********@tiscali.co.uk> posted :
On Sun, 12 Sep 2004 21:29:15 GMT, Bill Edwards <bi**********@ntlworld.com>

wrote:

I'm trying to produce an array of working days but want to force
Saturday and Sunday to return the date of the previous Friday, e.g.
Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
9/11/04 should return Friday 9/10/04.

I've tried getdate()-1 and getdate()-2 respectively but am getting
stack overflow errors. Am I doing anything wrong, or is this just not
possible?


Or something like this VB code?

Function LastBusDay(ByVal D As Date) As Date
Dim D2 As Variant
D2 = DateSerial(Year(D), Month(D) + 1, 0)
Do While Weekday(D2) = 1 Or Weekday(D2) = 7
D2 = D2 - 1
Loop
LastBusDay = D2
End Function


In a javascript newsgroup, there is much to be said for posting answers
in javascript. I don't know whether the FAQ actually says that, but I
believe that it implies it. If you were to read the FAQ, you might well
find a pointer to information helping with such questions.

Although it will not matter once, your VB is inefficient; it also
appears to address a different question.

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

P: n/a
JRS: In article <cl********************************@4ax.com>, dated
Sun, 12 Sep 2004 21:29:15, seen in news:comp.lang.javascript, Bill
Edwards <bi**********@ntlworld.com> posted :
I'm trying to produce an array of working days but want to force
Saturday and Sunday to return the date of the previous Friday, e.g.
Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
9/11/04 should return Friday 9/10/04.
You are posting from NTLworld, with a BST time-stamp; therefore, you
should not be using FFF dates. Follow ISO 8601:2000 / BS EN 28601:1992
or later. Even Americans should understand that format, since it is
ANSI X3.30-1985(R1991), FIPS PUB 4-1, 4-2 - the smarter ones actually
use it. You should use 4-digit years, too.

I've tried getdate()-1 and getdate()-2 respectively but am getting
stack overflow errors. Am I doing anything wrong, or is this just not
possible?


Yes, you are not showing what you have actually done. Probably you have
written a recursive routine which (sometimes?) never terminates.
Perhaps you used = to test equality, perhaps not.

A Date Object, D, can be reduced to Friday by
W = D.getDay()
if (W==0) D.setDate(D.getDate()-2)
if (W==6) D.setDate(D.getDate()-1)
or by
W = D.getDay()
D.setDate(D.getDate() - (W==0) - (W%6==0) )
or by
D.setDate(D.getDate() - [2,0,0,0,0,0,1][D.getDay()])
or by
while (D.getDay()%6==0) D.setDate(D.getDate()-1)

Read the FAQ carefully; see below. You may then find a better way.

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

P: n/a
Dr John Stockton wrote:
<snip>

A Date Object, D, can be reduced to Friday by
W = D.getDay()
if (W==0) D.setDate(D.getDate()-2)
if (W==6) D.setDate(D.getDate()-1)
or by
W = D.getDay()
D.setDate(D.getDate() - (W==0) - (W%6==0) )


W = D.getDay();
D.setDate(D.getDate() - (W==0) - (W%6==0) );
For some reason this solution induces in me a pleasant feeling.
Well done.
Mick
<snip>
Jul 23 '05 #9

P: n/a
Bill Edwards wrote:
I'm trying to produce an array of working days but want to force
Saturday and Sunday to return the date of the previous Friday, e.g.
Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
9/11/04 should return Friday 9/10/04.

I've tried getdate()-1 and getdate()-2 respectively but am getting
stack overflow errors. Am I doing anything wrong, or is this just not
possible?


From what I can tell without any source code, most certainly you
do something wrong. There is no built-in getdate() method (it's
`getDate()'), so it is likely that you are recursively calling
your own method. Stack overflow errors often indicate infinite
recursion.
PointedEars
--
Now better! It crashes 32% faster than Win95
Jul 23 '05 #10

P: n/a
Thomas 'PointedEars' Lahn wrote on 19 sep 2004 in comp.lang.javascript:
Stack overflow errors often indicate infinite
recursion.


I would suggest, Thomas,
that infinite recursion means no stack overflow error.

;-)

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.