MySQL time display help?
Posted: Mon Dec 06, 2010 7:44 pm
I'm trying to echo a last login date and time from MySQL. Here's the code:
<p>You last logged in
<?php echo $row_Recordset1['MONTHNAME(last_login)'];?>
<?php echo $row_Recordset1['DAYOFMONTH(last_login)'];?>
,
<?php echo $row_Recordset1['YEAR(last_login)']; ?>
<?php echo $row_Recordset1['HOUR(last_login)']; ?>
:
<?php echo $row_Recordset1['MINUTE(last_login)']; ?>
.
</p>
The code outputs the MySQL value of '2010-12-06 20:02:00' like this:
**You last logged in December 6, 2010 20:2.**
The problem I need to solve is that the MINUTE function returns a value in the range 1-59, and I need it to be 01-59. Also, I would prefer the hours to display in a 12-hour format instead of 24-hour (the output of HOUR function). I'm sure there's a simple solution to this, only I can't seem to figure it out.
Any assistance would be gratefully appreciated!
<p>You last logged in
<?php echo $row_Recordset1['MONTHNAME(last_login)'];?>
<?php echo $row_Recordset1['DAYOFMONTH(last_login)'];?>
,
<?php echo $row_Recordset1['YEAR(last_login)']; ?>
<?php echo $row_Recordset1['HOUR(last_login)']; ?>
:
<?php echo $row_Recordset1['MINUTE(last_login)']; ?>
.
</p>
The code outputs the MySQL value of '2010-12-06 20:02:00' like this:
**You last logged in December 6, 2010 20:2.**
The problem I need to solve is that the MINUTE function returns a value in the range 1-59, and I need it to be 01-59. Also, I would prefer the hours to display in a 12-hour format instead of 24-hour (the output of HOUR function). I'm sure there's a simple solution to this, only I can't seem to figure it out.
Any assistance would be gratefully appreciated!