rahish Posted June 7, 2006 Share Posted June 7, 2006 Hi,I am creating a simple CMS and want a date on each page to show the date the page was created.I have a timestamp set in the database for each new page id which sets the current timestamp when each entry is created but on pages.php it shows up with today's date not the created date.I have the page set up to retrieve the results of all page ids and I am trying to format it with the following example.[code]<?phpinclude('header.inc');$id = $_GET["page_number"];$query = "SELECT * FROM pages where page_id ='$id'"; //querying the database, selects a single page id$result = mysql_query($query) or die ("Couldn't execute query.");// Populate cells using a mysql_fetch_array script while ($row=mysql_fetch_array($result)){ $page_id=$row["page_id"]; $date=$row["date"]; $title=$row["title"]; $content=$row["content"]; $date =date("F j, Y, g:i a"); echo "<div id='content'><h3>$title</h3><br />$content<br /><p class='date'>Posted: $date</p></div>";//this prints the results from the mysql_fetch_array script on the screen}include('footer.inc');?>[/code]Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/11395-date-formatting-question/ Share on other sites More sharing options...
trq Posted June 7, 2006 Share Posted June 7, 2006 [code]$date = date("F j, Y, g:i a", $date);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11395-date-formatting-question/#findComment-42727 Share on other sites More sharing options...
rahish Posted June 7, 2006 Author Share Posted June 7, 2006 [!--quoteo(post=380925:date=Jun 7 2006, 03:59 AM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 7 2006, 03:59 AM) [snapback]380925[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]$date = date("F j, Y, g:i a", $date);[/code][/quote]Thanks Thorpe,I think that worked as expected and makes sense except the date is showingPosted: January 1, 1970, 1:33 am and in phpMyadmin it shows 2006-06-05 09:43:21 in the date field.I am running xammp on OSX localhost.Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/11395-date-formatting-question/#findComment-42730 Share on other sites More sharing options...
miz_luvly@hotmail.com Posted June 7, 2006 Share Posted June 7, 2006 [!--quoteo(post=380921:date=Jun 7 2006, 03:42 AM:name=rahish)--][div class=\'quotetop\']QUOTE(rahish @ Jun 7 2006, 03:42 AM) [snapback]380921[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi,I am creating a simple CMS and want a date on each page to show the date the page was created.I have a timestamp set in the database for each new page id which sets the current timestamp when each entry is created but on pages.php it shows up with today's date not the created date.I have the page set up to retrieve the results of all page ids and I am trying to format it with the following example.[code]<?phpinclude('header.inc');$id = $_GET["page_number"];$query = "SELECT * FROM pages where page_id ='$id'"; //querying the database, selects a single page id$result = mysql_query($query) or die ("Couldn't execute query.");// Populate cells using a mysql_fetch_array script while ($row=mysql_fetch_array($result)){ $page_id=$row["page_id"]; $date=$row["date"]; $title=$row["title"]; $content=$row["content"]; $date =date("F j, Y, g:i a"); echo "<div id='content'><h3>$title</h3><br />$content<br /><p class='date'>Posted: $date</p></div>";//this prints the results from the mysql_fetch_array script on the screen}include('footer.inc');?>[/code]Any ideas?[/quote]Hiif you have timestamp column in your database you need to take it out and display here . something like$date=$row["timestamp_col_name"]; it will be displayed yyyy/mm/dd format you can format it to dd/mm/yyyy using php."$date =date("F j, Y, g:i a");" is used to display current date. hope that helpssab Quote Link to comment https://forums.phpfreaks.com/topic/11395-date-formatting-question/#findComment-42732 Share on other sites More sharing options...
rahish Posted June 7, 2006 Author Share Posted June 7, 2006 [!--quoteo(post=380930:date=Jun 7 2006, 04:10 AM:name=sab)--][div class=\'quotetop\']QUOTE(sab @ Jun 7 2006, 04:10 AM) [snapback]380930[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hiif you have timestamp column in your database you need to take it out and display here . something like$date=$row["timestamp_col_name"]; it will be displayed yyyy/mm/dd format you can format it to dd/mm/yyyy using php."$date =date("F j, Y, g:i a");" is used to display current date. hope that helpssab[/quote]Not quite sure what you mean about Taking it out of the database.inside the fetch array, I can see that it could be formatted with a timestamp somehow[code]$date=$row["timestamp_col_name"]; [/code]but in this case that would make it[code]$date=$row["timestamp_date"];[/code]Which doesn't work shouldn't it be something more like[code]$date=$row(timestamp["date"]);[/code]I know that's not rightCould the select statement itself could be formatted in this way to display post dates with certain formatting? Quote Link to comment https://forums.phpfreaks.com/topic/11395-date-formatting-question/#findComment-42736 Share on other sites More sharing options...
miz_luvly@hotmail.com Posted June 7, 2006 Share Posted June 7, 2006 [!--quoteo(post=380934:date=Jun 7 2006, 04:45 AM:name=rahish)--][div class=\'quotetop\']QUOTE(rahish @ Jun 7 2006, 04:45 AM) [snapback]380934[/snapback][/div][div class=\'quotemain\'][!--quotec--]Not quite sure what you mean about Taking it out of the database.inside the fetch array, I can see that it could be formatted with a timestamp somehow[code]$date=$row["timestamp_col_name"]; [/code]but in this case that would make it[code]$date=$row["timestamp_date"];[/code]Which doesn't work shouldn't it be something more like[code]$date=$row(timestamp["date"]);[/code]I know that's not rightCould the select statement itself could be formatted in this way to display post dates with certain formatting?[/quote]hi u need to use DATE_FORMAT() functionyes u can use somethingl like:select table_name.*, DATE_FORMAT(col_name, '%d-%m-%Y') AS some_name from table_namehope it make sense this time sorry for the confusion. Quote Link to comment https://forums.phpfreaks.com/topic/11395-date-formatting-question/#findComment-42737 Share on other sites More sharing options...
rahish Posted June 7, 2006 Author Share Posted June 7, 2006 [!--quoteo(post=380935:date=Jun 7 2006, 04:55 AM:name=sab)--][div class=\'quotetop\']QUOTE(sab @ Jun 7 2006, 04:55 AM) [snapback]380935[/snapback][/div][div class=\'quotemain\'][!--quotec--]hi u need to use DATE_FORMAT() functionyes u can use somethingl like:select table_name.*, DATE_FORMAT(col_name, '%d-%m-%Y') AS some_name from table_namehope it make sense this time sorry for the confusion.[/quote]Thanks Sab that worked fine, except that %d-%m-%Yformats the result like this05-06-2006How do I change the letters to make it5th June 2006, at 11am or somethink like that?Rahish Quote Link to comment https://forums.phpfreaks.com/topic/11395-date-formatting-question/#findComment-42743 Share on other sites More sharing options...
trq Posted June 7, 2006 Share Posted June 7, 2006 [code]"%D %b %Y, at %l%p"[/code]There is a [a href=\"http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html\" target=\"_blank\"]manual[/a] you know? Quote Link to comment https://forums.phpfreaks.com/topic/11395-date-formatting-question/#findComment-42745 Share on other sites More sharing options...
miz_luvly@hotmail.com Posted June 7, 2006 Share Posted June 7, 2006 [!--quoteo(post=380941:date=Jun 7 2006, 05:57 AM:name=rahish)--][div class=\'quotetop\']QUOTE(rahish @ Jun 7 2006, 05:57 AM) [snapback]380941[/snapback][/div][div class=\'quotemain\'][!--quotec--]Thanks Sab that worked fine, except that %d-%m-%Yformats the result like this05-06-2006How do I change the letters to make it5th June 2006, at 11am or somethink like that?Rahish[/quote]good to hear that. OK here is a little secret (sssh)-- go here and choose whatever date format you like.[a href=\"http://www.mysqlfreaks.com/statements/59.php\" target=\"_blank\"]http://www.mysqlfreaks.com/statements/59.php[/a] Quote Link to comment https://forums.phpfreaks.com/topic/11395-date-formatting-question/#findComment-42747 Share on other sites More sharing options...
rahish Posted June 7, 2006 Author Share Posted June 7, 2006 Yes,Point taken I could have worked that out for myself, thanks for the help anyway.Rahish Quote Link to comment https://forums.phpfreaks.com/topic/11395-date-formatting-question/#findComment-42753 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.