garry Posted June 6, 2008 Share Posted June 6, 2008 So I store the date something was created in my database and it stores it like "0000-00-00 00:00:00". What I want to do is get this from the database and change it into "Wednesday 12th August" - that sorta format. Can anyone help? Quote Link to comment Share on other sites More sharing options...
Wolphie Posted June 6, 2008 Share Posted June 6, 2008 I take it you're using a unix timestamp to get that date format, i.e. using the timestamp data type in SQL. You can just use <?php $date = date('l jS F Y'); // Wednesday 12th August 2008 mysql_query("INSERT INTO `db_name` . `table_name` ( `field_name` ) VALUES ( '$date' )") or die('MySQL Error: ' . mysql_error()); ?> Check out http://uk2.php.net/manual/en/function.date.php Quote Link to comment Share on other sites More sharing options...
garry Posted June 6, 2008 Author Share Posted June 6, 2008 Ah yes, I am using a unix time stamp. I'm using the now() function to record the date and time. The only problem is that I already have a bunch of dates recorded in the database using that previously mentioned format, so how can I convert it to the new format from that? Quote Link to comment Share on other sites More sharing options...
Wolphie Posted June 6, 2008 Share Posted June 6, 2008 <?php error_reporting(E_ALL); $sql = mysql_query("SELECT `date` FROM `db_name` . `table_name`") or die('MySQL Error: ' . mysql_error()); while($row = mysql_fetch_array($sql)) { $exp = explode(' ', $row['date']); // Return the date only without the time. $date = date('l jS F Y', $exp[0]); print $date; // OR mysql_query("UPDATE `db_name` . `table_name` SET `date` = '$date'"); } ?> That should work, however don't hold me to it. Quote Link to comment Share on other sites More sharing options...
garry Posted June 6, 2008 Author Share Posted June 6, 2008 Hmm, the code you said didn't quite work The date it is getting from the database is "2008-06-06 23:02:58" When I use date('l jS F Y', $date) I get the following error: Notice: A non well formed numeric value encountered in /htdocs/dev/musicnews.php on line 103 Note - line 103 is the date() function Quote Link to comment Share on other sites More sharing options...
Wolphie Posted June 6, 2008 Share Posted June 6, 2008 <?php error_reporting(E_ALL); $sql = mysql_query("SELECT `date` FROM `db_name` . `table_name`") or die('MySQL Error: ' . mysql_error()); while($row = mysql_fetch_array($sql)) { // $exp = explode(' ', $row['date']); // Return the date only without the time. $date = date('l jS F Y', $row['date']); print $date; // OR mysql_query("UPDATE `db_name` . `table_name` SET `date` = '$date'"); } ?> Try that, sorry if i'm not being much help.. I'm at work so it's difficult for me to go in-depth. Quote Link to comment Share on other sites More sharing options...
garry Posted June 6, 2008 Author Share Posted June 6, 2008 Hmm, nope, still doesn't work. All I'm trying to do is turn this: "2008-06-06 23:36:41", into something like this "Friday 6th June 2008" I tried using that $date = date('l jS F Y', $row['date']); function but it just returns the same error: Notice: A non well formed numeric value encountered in /htdocs/dev/musicnews.php on line 103 Quote Link to comment Share on other sites More sharing options...
garry Posted June 7, 2008 Author Share Posted June 7, 2008 Anyone please? Quote Link to comment Share on other sites More sharing options...
T Horton Posted June 7, 2008 Share Posted June 7, 2008 Hi Change this: $date = date('l jS F Y', $row['date']); To this: $date = date("l jS F, Y", strtotime($row['date'])); Works for me. Best Regards Tom Quote Link to comment Share on other sites More sharing options...
garry Posted June 7, 2008 Author Share Posted June 7, 2008 That was it, thankyou! Quote Link to comment 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.