Jump to content

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']; ?>

 

 

 

Link to comment
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

Link to comment
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)

Link to comment
Share on other sites

  • 3 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.