Solved

php date day format easy

Posted on 2007-03-29
2
233 Views
Last Modified: 2013-12-13
I am developing a school website at http://www.llantwitschool.org.uk/ but my php skills are very limited. I would like to have the dates of the Important Dates section in a format so that days between 1 and 9 have leading zeros infront of them (e.g. 01 Mar 07 as opposed to 1 Mar 07)

Here is the code:




<!-- change styles if you want -->
<style type="text/css">

A:link {text-decoration: none; color: black;}
A:visited {text-decoration: none; color: black;}
A:active {text-decoration: none; color: black;}
A:hover {text-decoration: underline; color: red;}
.textevent {font-weight: bold;font-family: verdana,arial; font-size: 13px; color: #000000; }
.textdate {font-family: verdana,arial; font-size: 9px; color: #000000; }
.htop {font-family: arial; font-size: 13px; color: #000000; }


</style>


</head>





<body>









<?php

$now = date("Y-m-d", time());
$cmonth = date('n', time());
$nextmonth = mktime(1,1,1,$cmonth + 1,1);
$months = array(time(), $nextmonth);
list($ty, $tm, $td) = explode('-',$now); // ty=thisyear, etc. used for highlighting 'today'

foreach ($months as $mnth) {

        // THERE IS NO NEED TO EDIT BELOW HERE

        $mon = date("m",$mnth); // month from clicked month name
        $month = intval($mon); // var to use with month name array
        if (strlen($mon)==1) { $mon = "0". $mon; }
        $yr = date("Y",$mnth); // year from clicked month name

        include("cal_parms.php");
        include("./lang/dat_nam_en.php"); // load default language file so as not to mess anything upp with new text.
        include($dat_names); // retrieved from cal_parms.php as a 'language' file
        include("cal_db_conn.php");
        mysql_connect($db_host, $db_login, $db_pass) or die ("Can't connect!");
        mysql_select_db($db_name) or die ("Can't open database!");

        $min_dat = $yr. "-". $mon. "-01";
        $max_dat = $yr. "-". $mon. "-31"; //sloppy but effective

        // retrieve all events for the month

        error_reporting(0);

        $query = "SELECT * from $db_table WHERE date_format(ev_dat, '%Y-%m')='$yr-$mon' ORDER by ev_dat";
        $result = @mysql_db_query($db_name, $query);

        while ($myrow = mysql_fetch_array($result)) { // loop through all results
                $found = $myrow['ev_dat'];
                $pieces = explode("-", $found);
                $monum = intval($pieces[1]);
                $danum = intval($pieces[2]);

                $yr = date("y",$mnth);
                $mon = date("M",$mnth);

                echo "[<span class='textdate'>". $danum. " ". $mon. " ". $yr. "</span>] ::";
                echo "<span class='textevent'>". "&nbsp;". $myrow['ev_title']. "</span><br />";


                echo "<a href='javascript:winy(\"calendar/show-month.php?mon=$m&amp;yr=$y\")'>";
                echo "<span style='text-decoration:none'>". $mo[intval($m)]. " ". $y. "</span></a>";

                $i++;
        }

        if ($i==0) { echo "<h1>".$noEventsText." ". $mo[$month]. "</h1>"; }
        if ($sho == "1") {
                echo "";
        }
        else {
                echo "";
        }
}
?>


</body>

</html>





Many thanks
0
Comment
Question by:llantwit
  • 2
2 Comments
 
LVL 29

Expert Comment

by:TeRReF
ID: 18814706
See the other question :)
0
 
LVL 29

Accepted Solution

by:
TeRReF earned 50 total points
ID: 18814709
$danum = sprintf("%02d", intval($pieces[2]));
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

930 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

11 Experts available now in Live!

Get 1:1 Help Now