Jump to content

Archived

This topic is now archived and is closed to further replies.

bluedogatdingdong

Date formatting

Recommended Posts

I am trying to list a diary of events on my web site.

 

The date format is MySql is yyyy/mm/dd - 2004/07/26

 

I need to reformat the field on the web page to Monday 26 July 2004 for example

 

I've found all the variables to reformat is straight PHP speak

ie "l j F Y"

 

 

I've tried <?php echo date ("l j F Y", ($row_Recordset1['date'])); ?> but this returns Thursday 1 January 1970, which wasn't at all what I was expecting.

 

So what is the syntax to format the required field?

 

<?php echo $row_Recordset1['Date']; ?>

 

 

 

Share this post


Link to post
Share on other sites

Easy. Get the 40 extra server formats extention from big mac's and install. Drag date from applications panel onto page then use the available server formats in application panel listed in a dropdown beside the date record.

Share this post


Link to post
Share on other sites
I've tried <?php echo date ("l j F Y", ($row_Recordset1['date'])); ?> but this returns Thursday 1 January 1970, which wasn't at all what I was expecting.

This format is incorrect for the date you require. To get a true result you need to use strtotime like below with correct letters for your format.

<?php echo date('l, d F, Y',strtotime($row_Recordset1['date_added'])); ?>

 

Without the strtotime is UNIX format, but to format mySQL use the above. You will find this format produces :-

 

Day(test) Date(leading zero) Month(text) Long year

Thursday, 29 July, 2004

Share this post


Link to post
Share on other sites

Or you can format the date in the SQL query itself.

 

Example -

 

$query = "SELECT title, post, author, DATE_FORMAT(date_entered, '%W, %M %D, %Y') AS postdate";

 

That would format the SQL date to the format you want. Then when you want to display it you would use postdate instead of the row name the timestamp is in. Make sense?

 

-Mark B)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.