/    Sign up×
Community /Pin to ProfileBookmark

first sunday of a month

How would i go about finding the first sunday of a month?
I need it to be something like:

if (day==sunday && sunday==1’th of the month) sunday=1

I have:

var w = new Date();
var wd = u.getDay();

if (wd==0) do whatever // but need the first sunday of the month to so something else

need something like counting sundays:

var sd = ??? // sd = sunday

if (wd==0 && (sunday==1’th of month)) do something
if (wd==0 && (sunday!=1’th of month)) do something else

please help

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@Sup3rkirbyNov 15.2011 — This might not be the best way to achieve what you want but it should work none-the-less:
[CODE]
var d = new Date();
var first_week = d.getDate();
var the_day = d.getDay();

if(first_week <= 7 && the_day == 0)
{
// It's the first Sunday of the month
// Do more stuff here
}
[/CODE]
Copy linkTweet thisAlerts:
@JunkMaleNov 15.2011 — Check your PM.
Copy linkTweet thisAlerts:
@WoozymanauthorNov 15.2011 — ohh yes... so obvious! thanks!

I guess I was thinking too much about it! :-P
Copy linkTweet thisAlerts:
@JMRKERNov 15.2011 — Check your PM.[/QUOTE]

ohh yes... so obvious! thanks!

I guess I was thinking too much about it! :-P[/QUOTE]


Care to share?

?
Copy linkTweet thisAlerts:
@JunkMaleNov 15.2011 — Hes on about Sup3rkirby.
Copy linkTweet thisAlerts:
@007JulienNov 15.2011 — An other way
[CODE]var td=new Date(), y=td.getFullyear(),m=td.getMonth();
firstSunday=1;while (dy=new Date(y,m,firstSunday).getDay()!=0) firstSunday++;[/CODE]
Copy linkTweet thisAlerts:
@wbportNov 15.2011 — Find out what day of the week the first day of the month is. From there it is a short calculation to tell you the date of the next Sunday--unless [B]getDay()[/B] returns a zero, subtract its result from 7.
×

Success!

Help @Woozyman spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...