/    Sign up×
Community /Pin to ProfileBookmark

date of first x day of the week of month

Hi,
I’m looking to get a list of the date of the first x day of the week of the month i.e. the date of the first monday of each month 01/03/2005, 02/07/2005, 03/07/2005, 04/04/2005, etc.
Any help is appreciated.
Thanks.
ck213

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 29.2005 — [code=php]
$yr = 2005;
$dayName = "Monday";
for($mo = 1; $mo <= 12; $mo++)
{
for($day = 1; $day <=7; $day++)
{
$timestamp = mktime(1,1,1,$mo,$day,$yr);
if(date('l', $timestamp) == $dayName)
{
echo "<p>The first $dayName of ";
echo date('F', $timestamp);
echo " is " . date('m/d/Y', $timestamp) . ".</p>n";
break;
}
}
}
[/code]
Copy linkTweet thisAlerts:
@ck213authorSep 29.2005 — Thanks NogDog for the reply.

It worked great!

However, I changed the format in the date function from

date('m/d/Y', $timestamp) to

date('M n Y', $timestamp) and the day/date was incorrect.

Instead of the correct date (for my example) of Oct 6 2005 for the first Thursday of October 2005, Oct 10 2005 was displayed.

Why does the m/d/y format display the correct date and the M n Y format does not? Something specific to the mktime function?

Thanks in advance for any help.

ck213
Copy linkTweet thisAlerts:
@NogDogSep 29.2005 — "n" is month number. You probably want "j" for day of the month.
Copy linkTweet thisAlerts:
@ck213authorSep 29.2005 — DOH! I'm so embarrassed!

It works as planned now that I changed the n to j.

Thanks NogDog for catching my mistake.
×

Success!

Help @ck213 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.18,
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,
)...