• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

Echo several dates + data in separate monthly calendars

Hi,

I can't figure out what the best method is to echo some dates + some event data on 3 different monthly calendars.

Say i need to echo 15 dates, always for the nearest 3 months. Each month has 5 dates in it.

The result should look something like this, very simply said:

<div><h1>August</h1> <div>5x date</div> </div>
<div><h1>September</h1> 5x date </div>
<div><h1>October</h1> 5x date </div>

The month name needs to be printed also and the main div's are each separate calendar-layouts, the dates are accompanied with some event data.

The dates are stored as a Unix timestamp

How should i do this?
0
peps03
Asked:
peps03
1 Solution
 
lwadwellCommented:
Where are the dates coming from?  Is it a database table or an array in the script?

If it was flat array, perhaps like:
$dates = array(1344952800,1347285600,1351170000,1347631200,1347890400,
               1350997200,1345125600,1347544800,1345471200,1345644000,
               1347026400,1351083600,1345298400,1351256400,1351342800);
sort($dates); // sort it into order
$lastmth = "";
foreach ( $dates as $date ) {
    $currmth = date("F", $date);
    if ( $currmth != $lastmth ) {
        if ( $lastmth != "" ) echo "</div></div>"; // close the last div
        echo "<div><h1>$currmth</h1><div>";        // start a new month
    }
    echo "the ",date("jS", $date),"<br />";
    $lastmth = $currmth;
}

Open in new window

0
 
Ray PaseurCommented:
The dates are stored as a Unix timestamp
Life may be easier if the dates are stored in the ISO-8601 standard date/time string.  It will be visually obvious which dates are part of which month; that may not be so clear from a timestamp integer.

This article explains some of the things you may want to consider as you write the code.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
0
 
peps03Author Commented:
Sorry for the late reaction, lwadwell, but this did the trick!

Took some time to implement my calendar properly but it now works like a charm, thank you very much!

@Ray, i actually prefer the timestamp, very easy to calculate with and easy to retrieve dates with, in the exact way you want.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now