Page 1 of 1

Date Format

Posted: Fri Feb 20, 2004 9:06 am
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

Posted: Fri Feb 20, 2004 9:12 am
by markl999
What's the column type/format of the date column in the db?

Posted: Fri Feb 20, 2004 9:25 am
by fuzz
Just the standard: YYYY-MM-DD that comes standard out of the mySQL db.

Posted: Fri Feb 20, 2004 9:27 am
by markl999

Code: Select all

<?php
$date = '1971-09-30'; //this is your $row_Recordset1['date'];
echo date('d-m-Y', strtotime($date));
?>

Posted: Fri Feb 20, 2004 9:47 am
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;

Posted: Fri Feb 20, 2004 9:53 am
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.

Posted: Fri Feb 20, 2004 10:00 am
by liljester
SELECT TIME_FORMAT(time_field, "%I:%i%p") as some_time FROM table