Jump to content

[SOLVED] formatting date in a string. Help!


tqla

Recommended Posts

Hello, I need help with formatting the date in a string.

 

First of all I have this. As you can see, the Date is pulled from mysql.

 

foreach ($galleries as $gallery) {

  $gallery_id = $gallery['ID'];

  $gallery_catid = $gallery['CatID'];

  $gallery_catname = $gallery['CatName'];

  $gallery_catsubof = $gallery['CatSubOf'];

  $gallery_title = $gallery['Title'];

  $gallery_date = $gallery['Date'];

etc...

 

This string pulls from the DB and is the output.

 

  if ($gallery_content_array[$gallery_catname]) {

    $gallery_content_array[$gallery_catname] .= '' . $gallery_date . '<br>' . $gallery_venue . '<br>' . $gallery_address .'<br>' . $gallery_city . ', ' . $gallery_state . '<br>' . $gallery_phone . '<br>' . $gallery_url . '<br><br>';

 

 

It works fine except that the date reads like this:

 

2007-03-05 21:00:00

The Palace

1234 5th street

Culver City, CA

310-555-1212

 

I want the date to read like this, " 03-05-2007, 9:00PM"

 

I know that I need to add this somewhere (F j, Y, g:i) but I don't know where.

 

Please help. Thanks

Link to comment
https://forums.phpfreaks.com/topic/39861-solved-formatting-date-in-a-string-help/
Share on other sites

$gallery_date = date("F j, Y, g:i", strtotime($gallery_date)); //March 5, 2007, 9:00

or

$gallery_date = date("m-d-Y, g:ia", strtotime($gallery_date)); //3-05-2007, 9:00pm

 

Pick either one, depending on which you wanted. You asked for both.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.