toxictoad Posted December 5, 2008 Share Posted December 5, 2008 Hi, I've been searching for a way to format the date pulled from my database and I've found a lot of different info but I just can't understand how I adapt what I've found to fit into my current page/code? Like this thread: http://www.phpfreaks.com/forums/index.php/topic,123000.0.html and other refer to the strtotime and I found another that gives me the correct format $insert[review_date] = date("j F, Y",strtotime($insert[review_date])); will change it from 30/08/2005 to 30 August, 2005 So it looks like the format I want is "j F, Y" But how do I adapt it to fit into my code? <?php require('config.php'); $id = $_GET['id']; $sql = "SELECT * FROM rssfeeds WHERE NewsID = '$id'"; $res = mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_array($res)){ $title=$row['Title']; $pubdate=$row['PubDate']; $description=$row['Description']; $content=$row['Content']; $source=$row['Source']; } ?> Published: <?=$pubdate?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/135701-solved-date-format/ Share on other sites More sharing options...
Maq Posted December 5, 2008 Share Posted December 5, 2008 Have you tried: $pubdate = date("j F, Y",strtotime($pubdate)); echo $pubdate; ? Quote Link to comment https://forums.phpfreaks.com/topic/135701-solved-date-format/#findComment-707036 Share on other sites More sharing options...
gevans Posted December 5, 2008 Share Posted December 5, 2008 i think this is what you're looking for while($row=mysql_fetch_array($res)){ $title=$row['Title']; $pubdate=date("j F, Y",strtotime($row['PubDate'])); $description=$row['Description']; $content=$row['Content']; $source=$row['Source']; } Quote Link to comment https://forums.phpfreaks.com/topic/135701-solved-date-format/#findComment-707040 Share on other sites More sharing options...
Brian W Posted December 5, 2008 Share Posted December 5, 2008 is there a reason u are using mysql_fetch_array() rather than simply using mysql_fetch_assoc()? I'm not criticizing, just don't know what the advantage is for using mysql_fetch_array() .... Quote Link to comment https://forums.phpfreaks.com/topic/135701-solved-date-format/#findComment-707044 Share on other sites More sharing options...
gevans Posted December 5, 2008 Share Posted December 5, 2008 fetch_array gives you options as to how the array is stored (associate, numeric or both) where as fetch_array just returns the assoc so; $result = mysql_query("SELECT id, name FROM table"); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "ID: {$row['id']} Name: {$row['id']}"); } see how fetch_array can be set, the other options are MYSQL_NUM and MYSQL_BOTH Quote Link to comment https://forums.phpfreaks.com/topic/135701-solved-date-format/#findComment-707055 Share on other sites More sharing options...
PFMaBiSmAd Posted December 5, 2008 Share Posted December 5, 2008 What is the starting format in your database now? Quote Link to comment https://forums.phpfreaks.com/topic/135701-solved-date-format/#findComment-707057 Share on other sites More sharing options...
toxictoad Posted December 5, 2008 Author Share Posted December 5, 2008 Thanks all. $pubdate = date("j F, Y",strtotime($pubdate)); Gave me a wrong date but $pubdate=date("j F, Y",strtotime($row['PubDate'])); works perfect As for why the use of array() over assoc() I don't know, I'm really new to PHP and I'm just trying to piece things together. Both work (just tested) so someone with more PHP experience should be able to explain the difference I guess? Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/135701-solved-date-format/#findComment-707058 Share on other sites More sharing options...
gevans Posted December 5, 2008 Share Posted December 5, 2008 Thanks all. $pubdate = date("j F, Y",strtotime($pubdate)); Gave me a wrong date but $pubdate=date("j F, Y",strtotime($row['PubDate'])); works perfect As for why the use of array() over assoc() I don't know, I'm really new to PHP and I'm just trying to piece things together. Both work (just tested) so someone with more PHP experience should be able to explain the difference I guess? Thanks again! The one that didn't work didn't work because you put it on the wrong place Quote Link to comment https://forums.phpfreaks.com/topic/135701-solved-date-format/#findComment-707064 Share on other sites More sharing options...
Maq Posted December 5, 2008 Share Posted December 5, 2008 Thanks all. $pubdate = date("j F, Y",strtotime($pubdate)); Gave me a wrong date but $pubdate=date("j F, Y",strtotime($row['PubDate'])); works perfect As for why the use of array() over assoc() I don't know, I'm really new to PHP and I'm just trying to piece things together. Both work (just tested) so someone with more PHP experience should be able to explain the difference I guess? Thanks again! The one that didn't work didn't work because you put it on the wrong place Yeah, he probably put it in the while loop. Anyway, they are both pretty much the same thing, and both should work. Quote Link to comment https://forums.phpfreaks.com/topic/135701-solved-date-format/#findComment-707066 Share on other sites More sharing options...
toxictoad Posted December 5, 2008 Author Share Posted December 5, 2008 The one that didn't work didn't work because you put it on the wrong place Not because it doesn't contain the ($row part? Quote Link to comment https://forums.phpfreaks.com/topic/135701-solved-date-format/#findComment-707068 Share on other sites More sharing options...
toxictoad Posted December 5, 2008 Author Share Posted December 5, 2008 Thanks all. $pubdate = date("j F, Y",strtotime($pubdate)); Gave me a wrong date but $pubdate=date("j F, Y",strtotime($row['PubDate'])); works perfect As for why the use of array() over assoc() I don't know, I'm really new to PHP and I'm just trying to piece things together. Both work (just tested) so someone with more PHP experience should be able to explain the difference I guess? Thanks again! The one that didn't work didn't work because you put it on the wrong place Yeah, he probably put it in the while loop. Anyway, they are both pretty much the same thing, and both should work. I see...I did put it in the 'while loop' Doh! Quote Link to comment https://forums.phpfreaks.com/topic/135701-solved-date-format/#findComment-707069 Share on other sites More sharing options...
Maq Posted December 5, 2008 Share Posted December 5, 2008 Thanks all. $pubdate = date("j F, Y",strtotime($pubdate)); Gave me a wrong date but $pubdate=date("j F, Y",strtotime($row['PubDate'])); works perfect As for why the use of array() over assoc() I don't know, I'm really new to PHP and I'm just trying to piece things together. Both work (just tested) so someone with more PHP experience should be able to explain the difference I guess? Thanks again! The one that didn't work didn't work because you put it on the wrong place Yeah, he probably put it in the while loop. Anyway, they are both pretty much the same thing, and both should work. I see...I did put it in the 'while loop' Doh! Lol! This is what I meant... while($row=mysql_fetch_array($res)){ $title=$row['Title']; $pubdate=$row['PubDate']; $description=$row['Description']; $content=$row['Content']; $source=$row['Source']; } $pubdate=date("j F, Y",strtotime($pubdate)); echo "Published" . $pubdate; Quote Link to comment https://forums.phpfreaks.com/topic/135701-solved-date-format/#findComment-707075 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.