PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
fuzz
Forum Newbie
Posts: 3 Joined: Fri Feb 20, 2004 9:06 am
Post
by fuzz » Fri Feb 20, 2004 9:06 am
Hi all,
I am sort of new to this and I didn't really understand the manual's explanation.
I have this code:
Code: Select all
<?php echo $row_Recordset1ї'date']; ?>
Which displays the date in a table from my mysql db. I would like the results to be returned in the U.S. date format: MM-DD-YYYY.
What could I do to make this happen?
Thanks,
fuzz
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Fri Feb 20, 2004 9:12 am
What's the column type/format of the date column in the db?
fuzz
Forum Newbie
Posts: 3 Joined: Fri Feb 20, 2004 9:06 am
Post
by fuzz » Fri Feb 20, 2004 9:25 am
Just the standard: YYYY-MM-DD that comes standard out of the mySQL db.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Fri Feb 20, 2004 9:27 am
Code: Select all
<?php
$date = '1971-09-30'; //this is your $row_Recordset1['date'];
echo date('d-m-Y', strtotime($date));
?>
liljester
Forum Contributor
Posts: 400 Joined: Tue May 20, 2003 4:49 pm
Post
by liljester » Fri Feb 20, 2004 9:47 am
or you could format the date with mysql if its a datetime or timestamp.
SELECT DATE_FORMAT(date_field, "%m-%d-%Y") as some_date FROM table WHERE something=true;
fuzz
Forum Newbie
Posts: 3 Joined: Fri Feb 20, 2004 9:06 am
Post
by fuzz » Fri Feb 20, 2004 9:53 am
Worked, thanks! You rock!
Now, I tried to figure out displaying the time (from my database which is currently in 24 Hour format 24:00:00) to 'Hour:Minute AM/PM'
Code: Select all
<?php $time = $row_Recordset1ї'time'];
echo time('I:Mp', strftime($time)); ?>
But that was obviously not right. Sorry to bother you for one more code.
liljester
Forum Contributor
Posts: 400 Joined: Tue May 20, 2003 4:49 pm
Post
by liljester » Fri Feb 20, 2004 10:00 am
SELECT TIME_FORMAT(time_field, "%I:%i%p") as some_time FROM table