algorithm to display month from timestamp doesnt work???
Posted: Thu Nov 13, 2008 2:13 am
Hi. Im using mysql and I have a 'date' column in my 'Logs' table that is a timestamp. I tried to write this code to display the month as a string of characters rather than two numbers. Like usual i cant get it to work. Any help would be greatly appreciated.
Code: Select all
<?php
session_start();
include('connectDB.php');
//in the query below, 'date' is a mysql timestamp it goes 'yyy-mm-dd hh:mm:ss'
$query3 = 'SELECT MAX(date) FROM Logs WHERE id IN (SELECT id FROM Users WHERE id ='.$_SESSION['id'].')';
$result = mysql_query($query3);
$row = mysql_fetch_array($result);
$when = explode(' ',$row);
//this is where things go wrong. It does not give me what i want?? I threw in the echo just to see whats going on
echo $when[0];
echo $when[1];
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////
$date = $when[0];
$date2 = explode('-',$date);
$year = $date[0];
$month = $date[1];
$day = $date[2];
$months[0] = 'January';
$months[1] ='Febuary';
$months[2] = 'March';
$months[3] = 'April';
$months[4] = 'May';
$months[5] = 'June';
$months[6] = 'July';
$months[7] ='August';
$months[8] ='September';
$months[9] = 'October';
$months[10] ='November';
$months[11] ='December';
//supposed to display the name of the month
echo $months[$month];
?>