Hi All,
Looking for a simple function to return the date for the follwing Friday. I
send out emails from time to time and I would like a function that
dynamically returns the date for the follwing Friday. So no matter what day
I send it, it will dynamically calculate Friday's date. Also if I am sending
it on a Friday, I would like to return the current date, Saturday and later
will return next Friday's date. Thanks for any advice.
Kind Regards,
CK 11 15979
I wrote one that works.
function nextFriday()
{
var d = new Date();
switch (d.getDay())
{
case 0: d.setDate(d.get Date() + 5);
break;
case 1: d.setDate(d.get Date() + 4);
break;
case 2: d.setDate(d.get Date() + 3);
break;
case 3: d.setDate(d.get Date() + 2);
break;
case 4: d.setDate(d.get Date() + 1);
break;
case 6: d.setDate(d.get Date() + 6);
break;
}
return d;
}
"CK" <c_**********@h otmail.com> wrote in message
news:9x******** **********@news svr21.news.prod igy.com... Hi All, Looking for a simple function to return the date for the follwing Friday. I send out emails from time to time and I would like a function that dynamically returns the date for the follwing Friday. So no matter what day I send it, it will dynamically calculate Friday's date. Also if I am sending it on a Friday, I would like to return the current date, Saturday and later will return next Friday's date. Thanks for any advice.
Kind Regards, CK
CK wrote: I send it, it will dynamically calculate Friday's date. Also if I am sending it on a Friday, I would like to return the current date, Saturday and later will return next Friday's date. Thanks for any advice.
function nextDay(day){
var d = new Date;
(day = (Math.abs(+day || 0) % 7) - d.getDay()) < 0 && (day += 7);
return day && d.setDate(d.get Date() + day), d;
};
The day parameter ranges from 0 to 6.
--
Jonas Raoni Soares Silva http://www.jsfromhell.com
Lee wrote: CK said:
Hi All, Looking for a simple function to return the date for the follwing Friday. I send out emails from time to time and I would like a function that dynamically returns the date for the follwing Friday. So no matter what day I send it, it will dynamically calculate Friday's date. Also if I am sending it on a Friday, I would like to return the current date, Saturday and later will return next Friday's date. Thanks for any advice.
var d=new Date(); d.setDate(d.get Date()+(12-d.getDay())%7);
d is now the current date if it is Friday or the date of the next Friday.
Aw, what the heck, here's another based on a for loop:
for (var x=new Date(); x.getDay()!=5; x.setDate(x.get Date()+1)){}
alert('Next Friday is ... ' + x.getDate());
--
Rob
JRS: In article <9x************ ******@newssvr2 1.news.prodigy. com>,
dated Thu, 23 Feb 2006 18:53:57 remote, seen in
news:comp.lang. javascript, CK <c_**********@h otmail.com> posted : Looking for a simple function to return the date for the follwing Friday. I send out emails from time to time and I would like a function that dynamically returns the date for the follwing Friday. So no matter what day I send it, it will dynamically calculate Friday's date. Also if I am sending it on a Friday, I would like to return the current date, Saturday and later will return next Friday's date. Thanks for any advice.
Before posting to a newsgroup, one should seek and read the newsgroup
FAQ; see below.
I presume that you want to use local civil dates.
Ignore any "solutions" that you may be offered that contain, implicitly
or explicitly, the number 86400000. Any such is necessarily either
incompletely reliable or unduly long.
BTW, since yours appears to be a non-Web application it may be that you
should really have asked in one of the Microsoft scripting groups, where
most questions are about local execution under WSH.
The answer is given via the FAQ, in js-date7.htm#NPXD ; with D = new
Date() :-
// X = 0..6 = Sun..Sat
D.setDate( D.getDate() + (7+X-D.getDay())%7 )
Note : Many people are sometimes still active after midnight. If you
may be such, it could be wise to subtract say four hours before
executing the above. Your personal "day" will then run from 04:00 to
28:00, local.
--
© 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.
RobG wrote:
[...] Aw, what the heck, here's another based on a for loop:
for (var x=new Date(); x.getDay()!=5; x.setDate(x.get Date()+1)){} alert('Next Friday is ... ' + x.getDate());
And if the need is for *next* Friday's date if today is Friday, then:
for (var x=new Date(); x.setDate(x.get Date()+1) && x.getDay()!=5; ){}
alert('Next Friday\'s date is: ' + x.getDate());
--
Rob
CK wrote: I wrote one that works.
function nextFriday() { var d = new Date();
switch (d.getDay()) { case 0: d.setDate(d.get Date() + 5); break;
case 1: d.setDate(d.get Date() + 4); break;
case 2: d.setDate(d.get Date() + 3); break;
case 3: d.setDate(d.get Date() + 2); break;
case 4: d.setDate(d.get Date() + 1); break;
case 6: d.setDate(d.get Date() + 6); break; }
return d;
}
Date.prototype. getNextWkDay = function(iWkDay )
{
if (typeof iWkDay == "undefined"
|| typeof iWkDay != "number")
{
// Monday is the default
iWkDay = 1;
}
iWkday = Math.floor(iWkD ay);
var x = iWkDay - this.getDay(), d = this;
if (x != 0)
{
var iDate = this.getDate();
d = new Date(
this.getFullYea r(),
this.getMonth() ,
iDate,
this.getHours() ,
this.getMinutes (),
this.getSeconds (),
this.getMillise conds());
if (x < 0)
{
x += 7;
}
d.setDate(iDate + x);
}
return d;
};
// get next Friday's date
var dNextFriday = new Date().getNextW kDay(5);
[Top post]
Don't do that again. <URL:http://jibbering.com/faq/>
PointedEars
Thomas 'PointedEars' Lahn wrote: Date.prototype. getNextWkDay = function(iWkDay ) { if (typeof iWkDay == "undefined" || typeof iWkDay != "number") { // Monday is the default iWkDay = 1; }
iWkday = Math.floor(iWkD ay);
var x = iWkDay - this.getDay(), d = this; if (x != 0) { var iDate = this.getDate();
d = new Date( this.getFullYea r(), this.getMonth() , iDate, this.getHours() , this.getMinutes (), this.getSeconds (), this.getMillise conds());
if (x < 0) { x += 7; }
d.setDate(iDate + x); }
return d; };
// get next Friday's date var dNextFriday = new Date().getNextW kDay(5);
Date.prototype. getNextWkDay = function(iWkDay )
{
if (typeof iWkDay != "number" || iWkDay < 0)
{
// next Monday is the default
iWkDay = 1;
}
else
{
iWkday = Math.floor(iWkD ay) % 7;
}
var x = (iWkDay - this.getDay() + 7) % 7, d = this;
if (x != 0)
{
var iDate = this.getDate();
d = new Date(
this.getFullYea r(),
this.getMonth() ,
iDate,
this.getHours() ,
this.getMinutes (),
this.getSeconds (),
this.getMillise conds());
d.setDate(iDate + x);
}
return d;
};
// get next Friday's date
var dNextFriday = new Date().getNextW kDay(5);
PointedEars
Thomas 'PointedEars' Lahn wrote: Date.prototype. getNextWkDay = function(iWkDay ) { if (typeof iWkDay == "undefined" || typeof iWkDay != "number") { // Monday is the default iWkDay = 1; }
iWkday = Math.floor(iWkD ay);
var x = iWkDay - this.getDay(), d = this; if (x != 0) { var iDate = this.getDate();
d = new Date( this.getFullYea r(), this.getMonth() , iDate, this.getHours() , this.getMinutes (), this.getSeconds (), this.getMillise conds());
if (x < 0) { x += 7; }
d.setDate(iDate + x); }
return d; };
// get next Friday's date var dNextFriday = new Date().getNextW kDay(5);
Date.prototype. getNextWkDay = function(iWkDay )
{
if (typeof iWkDay != "number" || iWkDay < 0)
{
// next Monday is the default
iWkDay = 1;
}
iWkday = Math.floor(iWkD ay) % 7;
var x = (iWkDay - this.getDay() + 7) % 7, d = this;
if (x != 0)
{
var iDate = this.getDate();
d = new Date(
this.getFullYea r(),
this.getMonth() ,
iDate,
this.getHours() ,
this.getMinutes (),
this.getSeconds (),
this.getMillise conds());
d.setDate(iDate + x);
}
return d;
};
// get next Friday's date
var dNextFriday = new Date().getNextW kDay(5);
PointedEars
JRS: In article <rI************ *****@news.optu s.net.au>, dated Thu, 23
Feb 2006 23:39:03 remote, seen in news:comp.lang. javascript, RobG
<rg***@iinet.ne t.au> posted : RobG wrote: [...] Aw, what the heck, here's another based on a for loop:
for (var x=new Date(); x.getDay()!=5; x.setDate(x.get Date()+1)){} alert('Next Friday is ... ' + x.getDate());
And if the need is for *next* Friday's date if today is Friday, then:
for (var x=new Date(); x.setDate(x.get Date()+1) && x.getDay()!=5; ){} alert('Next Friday\'s date is: ' + x.getDate());
Other than
* Determining the start and end of local Summer Time
according to the OS,
* Generating a list-type result,
is there any date/time calculation possible in javascript that *needs*
iteration?
--
© 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: J. Muenchbourg |
last post by:
Looking thru my resources, I cannot find a simple way of displaying next
sunday's date depending on what todays date is. I'd like to do it
without doing 7 if statements or case select:
todaysdate = now
sundaysdate = weekday(todaysdate + ?)
??
muench
|
by: Adrian |
last post by:
I hit on this problem converting a VB.NET insurance application to C#.
Age next birthday calculated from date of birth is often needed in
insurance premium calculations.
Originally done using DateDiff in VB.NET which is only available in C#
if you don't mind linking in Microsoft.VisualBasic.dll to your C#
application.
I wanted to avoid this so set about a pure C# solution which uses a
combination of TimeSpan in whole days and the...
|
by: vj |
last post by:
I'm doing:
a = now()
delta = ReltaiveDateTime(days=+6, weekday(mx.DateTime.Friday, 0))
Next Friday: a+delta
a: march 23
a+delta: Gives me March 31st and not March 24th
Any ideas?
|
by: Kentor |
last post by:
does anyone know of a script that would produce a calendar starting
from todays date with checkboxes next to every day of the month so that
the user is able to check it in case of an event for that day...
without specifying what the event is... just a simple checkbox..
|
by: shankindc |
last post by:
Hi,
I have the following requirements
In a form, there exists a date field which needs to be automatically populated. The date has to be the Friday of every week. Assume in a calendar week Feb 4th - Feb 11th, if the user opens a form for data entry anytime between Feb 4th(Sunday) - Feb 9th (Friday), the data field should populate with Feb 9th date. If the user opens the form anytime after Feb 9th, the date field should populate with the next...
| |
by: Matt |
last post by:
I have table that has the following fields:
JobNumber
WeekEndingDate
ReportRequired_01
ReportRequired_02
every Friday morning the weekending date changes. I need to
automatically generate a new record for each record that has a job
number and weekending date for the new weekending date.
|
by: Chris |
last post by:
I need to find a way to write a query that will return the date of the
Friday of four weeks ago. So, if I use today's date (7/30), I should
be returning 7/6 as 4 weeks ago on Friday. Any help is appreciated.
|
by: -Lost |
last post by:
I'm REALLY liking this so far. And for those who welcome something a
little less cryptic than what the resident date guru offers, here's a
chance to try something fairly elegant and definitely unique.
http://www.datejs.com/
--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
|
by: ncsthbell |
last post by:
I am having problems getting the end date to calculate correctly.
I start with Quarter '03/02', (YY/QTR), for this it means it is for the 2nd qtr of 2003. My goal is to get the begin & end dates for each 'month' in the quarter, hence, I want to calculate the begin & end of the month dates for April, May & June 2003 :
so my starting point is:
firstMonthBegin = vcBegMM & "/" & vcBegDD & "/" & vcBegYY
firstMonthEnd = vcEndMM &...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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...
|
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,...
|
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...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |