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 1112515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:43:30+00:00 2026-05-17T02:43:30+00:00

This is the calendar script I got from an online tutorial. It works fine

  • 0

This is the calendar script I got from an online tutorial. It works fine but I want to move the column of Sunday to the end (after the column of Saturday):

<?php
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"]))  $_REQUEST["year"]  = date("Y");

$month_current = $_REQUEST["month"];
$year_current  = $_REQUEST["year"];

$prev_year = $year_current;
$next_year = $year_current;

$month_previous = $month_current-1;
$month_next = $month_current+1;

if ($month_previous == 0 ) 
{
 $month_previous = 12;
 $prev_year = $year_current - 1;
}

if ($month_next == 13 ) 
{
 $month_next = 1;
 $next_year = $year_current + 1;
}

$timestamp = mktime(0,0,0,$month_current,1,$year_current);
$lastdate    = date("t",$timestamp);

$thismonth = getdate ($timestamp);
$firstday  = $thismonth['wday'];
?>

<?php 
for ($i=0; $i<($lastdate + $firstday); $i++) 
{

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

 if($i < $firstday) echo "<td></td>\n";

 else echo "<td align='center' valign='middle' height='20px'>". ($i - $firstday + 1) . "</td>\n";

 if(($i % 7) == 6 ) echo "</tr>\n";

}
?>

I tried to change the code into this:

<?php 
for ($i=0; $i<($lastdate + $firstday); $i++) 
{

 if(($i % 7) == 1 ) echo "<tr>\n";

 # if $i less than the first day (1), don't print the value of $i
 if($i < $firstday) echo "<td></td>\n";

 # print the value of $i
 else echo "<td align='center' valign='middle' height='20px'>". ($i - $firstday + 1) . "</td>\n";

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

}
?>

It then does not display properly in the column when the first day starts from Sunday. For instance: http://ec-ener.eu/dump/index.php?month=8&year=2010

How can I fix it? Alternatively, how can I change the original script so that I can move Sunday to the end of the columns?

p.s. I also just found out that the original code seems to have a bit problem/ bug, if you check the html – tr and td – it generates,

<tr>
<td align='center' valign='middle' height='20px'>30</td>
<td align='center' valign='middle' height='20px'>31</td>


                              </table>
            </td>
        </tr>

it has the closing table in the and there is only a closing but no opening. I believe that the original single simple loop generates some invalid html! can I fix it?? thanks!

  • 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-05-17T02:43:31+00:00Added an answer on May 17, 2026 at 2:43 am

    I think you need to change the firstday variable value for 1st day

    $firstday  = $thismonth['wday']; //from here
    //adding
    $firstday = ($firstday + 6) % 7; //shifting the 1st day
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this jquery script, it seems to be working in other browser, but
my calendar script works perfectly fine until I include it into my template. html
Given this markup: // Calendar.html?date=1/2/2003 <script> $(function() { $('.inlinedatepicker').datepicker(); }); </script> ... <div class=inlinedatepicker
I recently downloaded an event calendar from this link: http://www.asp.net/downloads/starter-kits/club/EventCalendar.zip I want to use
<script type=text/javascript> $(function() { $('#wp-calendar a').click(function(event) { event.preventDefault(); var url = $(this).attr('href') + '
I have jquery calendar code like this <script> $(document).ready(function() { $('#calTwo').jCal({ day: new Date(
I want to add events to my outlook calendar from the php code. As
So I had this working perfectly fine, but now for some reason I can't
I am generating events on fullCalendar with this code <script type=text/javascript> $(document).ready(function() { $('#calendar').fullCalendar({
The reason I want to do this is that I'm writing a script for

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.