Date Format

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

Post Reply
fuzz
Forum Newbie
Posts: 3
Joined: Fri Feb 20, 2004 9:06 am

Date Format

Post by fuzz »

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&#1111;'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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

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 »

Just the standard: YYYY-MM-DD that comes standard out of the mySQL db.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Code: Select all

<?php
$date = '1971-09-30'; //this is your $row_Recordset1['date'];
echo date('d-m-Y', strtotime($date));
?>
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

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 »

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&#1111;'time']; 
echo time('I:Mp', strftime($time)); ?>
But that was obviously not right. Sorry to bother you for one more code.
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

SELECT TIME_FORMAT(time_field, "%I:%i%p") as some_time FROM table
Post Reply