Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8013425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:37:45+00:00 2026-06-04T19:37:45+00:00

Here is my problem all months start from day 1 but month 7 2012

  • 0

Here is my problem
all months start from day 1
but month 7 2012
start from day 2
don’t know why

and here is the code

<table>
<?php
$cMonth = 7;
$cYear = 2012;

$first_day_timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday              = date("t",$first_day_timestamp);
$thismonth           = getdate($first_day_timestamp);
$startday            = $thismonth['wday'] - 1;

for ($i=0; $i<($maxday+$startday); $i++) {

    if (($i % 7) == 0 )  echo "<tr>";

    if ($i < $startday) { echo "<td>&nbsp;</td>" ; continue; }

    $current_day = $i - $startday + 1;

    echo "<td>". $current_day . "</td>";

    if (($i % 7) == 6 ) echo "</tr>";
}
?>
</table>

Image attached

Calendar

Please tell me why this happened

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:37:46+00:00Added an answer on June 4, 2026 at 7:37 pm

    Why are you doing this:

    $startday            = $thismonth['wday'] - 1;
    

    ??

    You’re moving the day offset back one. This is effectively saying the day you want to start counting on is one day before the first day of the month.

    –EDIT–
    So you’re doing that because you want the calendar to start on Monday instead of Sunday. php’s wday is this:

    0 (for Sunday) through 6 (for Saturday)

    You’re subtracting one from it will shift the start of the month down one day until and unless the month starts on Sunday. Then $startday is -1 and it throws off your counting. You need it to wrap around to the previous week instead. If you add another line that fixes this case like:

    $startday = thismonth['wday'] - 1;
    if($startday < 0 ) $startday = 6;
    

    It should fix the problem. I’m sure there’s other ways to compensate for Monday being the first day of the week though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It is Hallowe'en after all. Here's the problem: I'm maintaining some old-ish J2EE code,
date here my problem: String datetime = 2012-03-24 23:20:51; I know that that string
enter code here My problem is this: in this database the junction table contains
I have the following query: SELECT location, step, COUNT(*), AVG(foo), YEAR(start), MONTH(start), DAY(start) FROM
I was given good direction to solve a problem today from here but I
IDE = VS7 or 2002 Hi all, I have a really weird problem here.
What is the problem here? (Besides having redundant code). $.getJSON works as expected. However
I am experiencing a problem with the code below. It's converting milliseconds to months,
I have a PHP calendar that lists all of the days of the month
Hey all, got one mountain of a problem here. I have completed a program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.