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!
MySQL time display help?
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: MySQL time display help?
One of several ways to do this is:
Code: Select all
<?php echo $sprintf('%02u', row_Recordset1['MINUTE(last_login)']); ?>(#10850)