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? Link to comment https://forums.phpfreaks.com/topic/108972-solved-outputting-date-very-simple/ 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 Link to comment https://forums.phpfreaks.com/topic/108972-solved-outputting-date-very-simple/#findComment-559064 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? Link to comment https://forums.phpfreaks.com/topic/108972-solved-outputting-date-very-simple/#findComment-559067 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. Link to comment https://forums.phpfreaks.com/topic/108972-solved-outputting-date-very-simple/#findComment-559075 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 Link to comment https://forums.phpfreaks.com/topic/108972-solved-outputting-date-very-simple/#findComment-559086 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. Link to comment https://forums.phpfreaks.com/topic/108972-solved-outputting-date-very-simple/#findComment-559095 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 Link to comment https://forums.phpfreaks.com/topic/108972-solved-outputting-date-very-simple/#findComment-559130 Share on other sites More sharing options...
garry Posted June 7, 2008 Author Share Posted June 7, 2008 Anyone please? Link to comment https://forums.phpfreaks.com/topic/108972-solved-outputting-date-very-simple/#findComment-559766 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 Link to comment https://forums.phpfreaks.com/topic/108972-solved-outputting-date-very-simple/#findComment-559767 Share on other sites More sharing options...
garry Posted June 7, 2008 Author Share Posted June 7, 2008 That was it, thankyou! Link to comment https://forums.phpfreaks.com/topic/108972-solved-outputting-date-very-simple/#findComment-559774 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.