Jump to content

Recommended Posts

Hi All!

This is my second week of PHP. I'm going through a PHP course at the moment so i'm pretty certain i've made a stupid mistake somewhere!

 

I'm trying to get a date that's entered in my CMS panel to show on the front-end.

 

I've defined the variable departure_date --> got the raw data --> created a new date object --> tried to display the date object in the format j M Y.

 

I believe there is something wrong with how i am defining the date object in my echo statement.

 

I forgot to mention this is a wordpress website i'm working on with ACF custom fields if that helps.

$departure_date = get_field('departure_date', false, false);
$departure_date = new DateTime($departure_date); 
$cruise_line = get_field('cruise_line');
$ship = get_field('ship');

if(get_field('ship'))
{
    echo 'Departs' . $departure_date->format('j M Y') . get_field('cruise_line') . ' | ' . get_field('ship');

}
Edited by CruisePlus
Link to comment
https://forums.phpfreaks.com/topic/302887-php-date-formatting/
Share on other sites

What is the date format used in the database table? ie What do you get if you echo $departure_date immed after the get_field()?

// MySQL DATE type
$date = '2017-01-06';
$dt = new DateTime($date);
echo $dt->format('j M Y') . '<br>';

// Unix epoch integer type
$date = 1483660800;
$dt = new DateTime("@$date");
echo $dt->format('j M Y') . '<br>';

Edited by Barand
add code
Link to comment
https://forums.phpfreaks.com/topic/302887-php-date-formatting/#findComment-1541135
Share on other sites

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.