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

how to find dates of sundays in javascript?

nirmalsingh
218 100+
hi all!

I want to find dates of sundays in a particular year. help me with sample code. thanx in advance.
May 8 '07 #1
6 7787
mrhoo
428 256MB
Months in javascript Date objects are returned as the integers 0-11,
with 0 being January, 1 February, and so on.
Weekdays are also 0 based- Sunday is 0, Monday is 1.

To return an Array of all of the Sundays in a given year-

1. Create a date object for January 1 of that year.
2. If the weekday (Date.getDay()) is NOT Sunday (0), set the Date to the next date that is .
This gives you a Date object for the first Sunday of the year, which is the first member of your array.
3. Fill the Array by repeatedly adding 7 to the date, until the next Sunday falls in the next year.
Expand|Select|Wrap|Line Numbers
  1. function getSundays(y){
  2.     y=y|| new Date().getFullYear();
  3.     var A=[];
  4.     var D=new Date(y,0,1)
  5.     var day= D.getDay();
  6.     if(day!=0) D.setDate(D.getDate()+(7-day));
  7.     A[0]=D.toLocaleString();
  8.     while(D){
  9.         D.setDate(D.getDate()+7);
  10.         if(D.getFullYear()!=y) return A;
  11.         A.push(D.toLocaleDateString());
  12.     }
  13. }
What you save in the Array is up to you-
this example saves a locally formatted string,
but you could extract just the month and date-
A.push((D.getMonth()+1+' '+D.getDate()).
May 8 '07 #2
nirmalsingh
218 100+
hai all,
i want to find the dates of sundays in a year. how to do this? and how to find what day is 9 may 2007?
i need the result as Wednesday.
May 9 '07 #3
acoder
16,027 Expert Mod 8TB
Threads merged because they were on the same topic.
May 9 '07 #4
acoder
16,027 Expert Mod 8TB
hai all,
i want to find the dates of sundays in a year. how to do this? and how to find what day is 9 may 2007?
i need the result as Wednesday.
See the post by mrhoo for the first question.

For 9 May 2007, set the date using the methods of the Date object - see link Then use the getDay() ethod to get the day.
May 9 '07 #5
hi, How to Find The Sturdays And Sundays In between the given two days.
May 17 '07 #6
acoder
16,027 Expert Mod 8TB
hi, How to Find The Sturdays And Sundays In between the given two days.
Sunday is 0, so Saturday is 6. Just look for those two and keep adding 6 and 1 to get the weekend days until you get past the second date.
May 17 '07 #7

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

Similar topics

10
by: Colin Steadman | last post by:
I'm a stupid ASP programmer and I dont do Javascript (except for very simple tasks anyway), and I'm in a bit of a predicament. I've used a javascript table sorting script from here: ...
3
by: Tom Meerstad | last post by:
Hello, I am using a calender which begins with a sunday, but I would like it to begin with monday. The author's mail address isn't working (mail got bounced) so I'm really hoping anyone here...
8
by: MLH | last post by:
Anybody's solution would be appreciated. Pls, do not pause to write anything for this. I'm not looking for that kind of a handout. I have an idea about how to do it, but I wanted to see if anyone...
2
by: MLH | last post by:
With a table of holidays and A97's date fn's - how best to count weekends and holidays between two dates? My holiday table has 4 fields. I will be adding records to it each year as info becomes...
4
nirmalsingh
by: nirmalsingh | last post by:
hi all! i have to find the dates of sundays in a year. help me with sample code in C#. thanx in advance.
1
by: karunajo | last post by:
hi, I am giving two dates as input.Iwant to calculate the number of days between those days except sundays.How can i do it.. Help me..
1
by: burnspaul | last post by:
I need to input a date into one field and have access show me a another date (plus 20 days) in another field (which I can do) but here is where I need help. I need to exclude Saturdays & Sundays...
3
by: iceone | last post by:
Hi everybody, I am monitoring a call center and i need to calculate the working hours between the moment the call is answered and the moment the call is closed. i need to calculate the working...
1
by: Pradeepa01 | last post by:
Hi, We are facing an issue with the JDBC query, I need help on. I have 3 fields, UPC_ID, QTY,Date I have to retrieve all the records for one UPC_ID whose QTY is same for last five days. The...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.