Jump to content

[SOLVED] formatting date in a string. Help!


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.