Echo several dates + data in separate monthly calendars

Posted on 2012-08-26
Last Modified: 2012-08-28

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?
Question by:peps03
    LVL 25

    Accepted Solution

    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,
    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

    LVL 107

    Expert Comment

    by:Ray Paseur
    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.

    Author Closing Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    The viewer will learn how to dynamically set the form action using jQuery.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now