Jump to content


Photo

Date formatting


  • Please log in to reply
5 replies to this topic

#1 bluedogatdingdong

bluedogatdingdong
  • Members
  • PipPip
  • Member
  • 10 posts
  • LocationPenzance, Cornwall

Posted 26 July 2004 - 11:53 AM

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




#2 morpheus.100

morpheus.100
  • Members
  • PipPipPip
  • Advanced Member
  • 145 posts

Posted 30 July 2004 - 03:10 PM

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.

#3 morpheus.100

morpheus.100
  • Members
  • PipPipPip
  • Advanced Member
  • 145 posts

Posted 30 July 2004 - 03:40 PM

And if you cant find it pm me. I'll post it.

#4 morpheus.100

morpheus.100
  • Members
  • PipPipPip
  • Advanced Member
  • 145 posts

Posted 30 July 2004 - 07:22 PM

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

#5 CrystalSkull

CrystalSkull
  • Members
  • Pip
  • Newbie
  • 1 posts

Posted 30 July 2004 - 07:25 PM

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)

#6 bluedogatdingdong

bluedogatdingdong
  • Members
  • PipPip
  • Member
  • 10 posts
  • LocationPenzance, Cornwall

Posted 17 August 2004 - 01:30 PM

Thanks for all your replies - I used the SQL option in the end.
I should have known, I done it once before, and forgot!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users