GET the DATE and replace for text

I need to replace the dates with this format (year/month/day) in text like: September 2013


Here is an extract of the code:

      
mysql_data_seek ($result, 0);
	while ($row = mysql_fetch_assoc ($result)) {
   //get the publisher name
  $organizerSql = mysql_query("SELECT nazwa FROM baza_obiektow_inne WHERE id=" . $row['organizer_id'] . " LIMIT 1");
   $organizer = mysql_fetch_assoc($organizerSql);

   echo "<tr>\n";
   printf("<td><a href='http://embs-group.com/%s,%s'>%s</a></td>", $row['id'], str_replace(" ", "_", $row['name']), $row['name']);
   printf("<td>%s</td>", $organizer['nazwa']);
   printf("<td>%s</td>", $row['no_pages']);
   printf("<td>%s</td>", $row['publication_date']); // Here is where I get the date 
   printf("<td>%s</td>", $row['price']);
   printf("<td>%s</td>", $row['currency']);
  
   echo "</tr>\n";

Open in new window

Klaus AndersenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Marco GasiFreelancerCommented:
$year = substr($row['publication_date'], 0, 4);
$month = substr($row['publication_date'], 5, 2);
switch ($month) {
  case '01':  
      $month = 'january';
      break;
  case '02':  
      $month = 'february';
      break;  
  case '03':  
      $month = 'march';
      break;
  // and so on...
}

Then:

printf("<td>%s</td>", $month . " " . $year); // Here is where I get the date

I didn't test this but I think it should work :)

Cheers
0
Ray PaseurCommented:
The date columns in the database should be of the type DATE or DATETIME.  They will come back to your PHP script in the form of the ISO-8601 date/time string.  You use strtotime() and date() to convert these values into "pretty dates" for public display.  Example:

$pretty_date = date('F Y', strtotime($row['publication_date']));
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Klaus AndersenAuthor Commented:
Excellent Ray, that´s exactly what I needed. I was trying to get the text value for the dates from a table I created specially for that. But your solution is much smarter and simply. Many thanks!
0
Ray PaseurCommented:
Thanks for the points.  The advantage of using the built-in PHP functions (over the text string manipulation) begins to be obvious when you need to start doing arithmetic with dates, like "Next Wednesday."
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.