/    Sign up×
Community /Pin to ProfileBookmark

hi,

can anyone help me…

how to get the sunday day for the whole next month…..?

for example:
next month is july..then how to get the day of the sunday day for the whole july?

thanks…..

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@crh3675Jun 16.2004 — <i>
</i>&lt;script type="text/javascript"&gt;
var d=new Date();
var sundays=Array();

var month=3;
var year=2004;

d.setMonth(month-1); // Javascript starts months at 0
d.setYear(year);

for(i=1;i&lt;=31;i++){
var m=d.getMonth();
if(m==(month-1)){
d.setDate(i);
if(d.getDay()==0){
sundays[sundays.length]=month+"/"+i+"/"+year;
}
}else{
break;
}
}

for(i=0;i&lt;sundays.length;i++){
alert(sundays[i]);
}
&lt;/script&gt;


Oops. That's javascript. But you can use the same concept for PHP.

<i>
</i>&lt;?
$date="4/1/2004";

$timestamp=strtotime($date);
$m=date("m",$timestamp);
$sundays=Array();

for($i=1;$i&lt;=31;$i++){

<i> </i>$temptime=mktime(0,0,0,date("m",$timestamp),$i,date("Y",$timestamp));
<i> </i>if($m==date("m",$temptime)){
<i> </i> if(date("w",$temptime)==0){
<i> </i> $sundays[count($sundays)]=date("m/d/Y",$temptime);
<i> </i> }
<i> </i>}else{
<i> </i> break;
<i> </i>}
}

for($i=0;$i&lt;count($sundays);$i++){
echo $sundays[$i]."&lt;br/&gt;";
}
?&gt;


Copy linkTweet thisAlerts:
@r3sannauthorJun 16.2004 — thank u

the ultimate web nerd....


thanks a lot ..

r3sann
×

Success!

Help @r3sann 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.20,
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,
)...