RobsonLittle Red Book ▸ Dates

Chapter 2 - Question 3

Given three integers representing a day, month and year - eg:

13 11 1983

Output the date as dd/mm/yy - i.e., 13/11/83

Solution 1

<?    // use the current day as the day to use    // the day and month here do have leading zeros when necessary    $day = date(d);    $month = date(m);    $year = date(Y);        // this solution is very simple, perhaps i should do some validation here        // output the day, month and the last two digits of the year    echo $day . '/' . $month . '/' . substr($year, 2, 2);     ?>

Which produces:

28/11/20

Log

© 2004-20 robson | cc unless stated