Wordpress ACF - Date format - php

I am using the date field to render out the date to look like: 11/15/2014. But I want to also display the date like November 15, 2014 else where on the page. Is it somehow possible to render out the date in two different formats?
<?php the_field('date'); ?>

You can use get_field and then you can change the date format to whatever you want.
$date = get_field('date');
$date2 = date("F j, Y", strtotime($date));

For 11/15/2014,
the_date('m/d/Y');
And for November 15, 2014,
the_date('F d, Y');

Related

How to Display date as day/month/year

I want to display my date as day/month/year.
example 31st October 2011
echo '<h4>Date Of Birth: '.$row['dob'].'</br></h4>';
You can try below code ::-
echo '<h4>Date Of Birth: '.date('dS F Y', strtotime($row['dob'])).'</br></h4>';
// ^^^^^^^ Here the is format of date, in which format you want.
Output will be ::-
31st October 2011
For more you can refer click here
<?php
$mydate = "2010-03-3";
$newDate = date("d M Y", strtotime($mydate));
$new_date = date('dS F Y', strtotime($newDate));
echo $new_date;
?>
/*Out Put*/
03rd March 2010
So if you have that data stored as or you can convert it to 3 variables representing DD MM YYYY then I'd suggest creating array of months and an array of post-fixes(don't know how to call it, but in your example it's 31st) and getting DD % 10 to use reminder for post-fix array
$month = ['January','February',....,'December']; //remember it's $month[MM-1];
$post = ['th','st','nd',...,'th'] //not sure if this on is correct but hope you get the idea
echo date('dS F Y', strtotime($row['dob']));
Refer to DateTime. I normally avoid strtotime() conversions.
Heres a working solution:
<?php
$date = '2016-11-12';
$newDate = new DateTime($date);
echo $newDate->format('jS F Y');
?>
OUTPUT:
12th November 2016

PHP format date is displaying wrong

I'm trying to format a date from a post variable. When you type in: 05-05-2016 it will display as May 5, 2016. But when you type 05-12-2016, it will display as December 5, 2016. The format is below:
echo date("F d, Y", strtotime($wedding_date));
The format I would like is: Month Day, Year
echo date_format(date_create_from_format('m-d-Y', $wedding_date), 'F d, Y');
and adjust 'm-d-Y' to your needs (or input).
Obviously there is an ambiguity in the input.
So strtotime does not know what input format you delivered.
You may consider using DateTime instead.
$out = DateTime::createFromFormat('d-m-Y', $weddingDay);
echo $out->format('F d, Y');

Display todays day of the week, month, day, year in THIS format in PHP?

I would like to display this format of the current date using PHP. I have googled and found a few variances of what I want to do but the company I work for wants it specifically in this format to match what they've mailed out.
Monday, March 16, 2015
Thanks.
If you looked at the PHP documentation for date you'd be able to figure it out very easily:
echo date('l, F j, Y');
which outputs
Monday, March 16, 2015
As mentioned by #alfallouji, you should have a look at the php documentation.
Here is what you need:
$now = new \DateTime();
echo $now->format('l, F j, Y');
The date format string should be "l, F d, Y".
You can display current date in this format as below:
<?php
echo date("l, F d, Y");
?>

How to format date yy-mm-dd in PHP

I have dates currently in this format: yy-mm-dd (e.g. 2011-11-18)
I want them in this format: Friday 18 November 2011
I've tried reading through the PHP documentation manual, but I can't see how to manage dates in the format that I have. If the date needs to be in a different order I can arrange that, but I'm a bit stuck at the meoment.
Any help would be much appreciated.
Use PHP5s new date classes. Much cleaner:
$date = DateTime::createFromFormat('Y-m-d', '2011-11-18');
echo $date->format('l d F Y');
date('l j F Y', strtotime($date));
Just use starttime to change the the dates in many formats using this link.
echo date('l d F Y');
gives you the date format you want.
This was all in the manual you yourself linked.
just use strtotime to get back a timestamp and then use date() to format that:
$date = '2011-11-18'; // your date
$timestamp = strtotime($date); // convert to a timestamp
$new_date = date('l j F Y',$timestamp) // format timestamp
echo $new_date;

Simple PHP date question

I have the following string:
$date = 2011-08-29 14:53:15;
when I do this:
echo date('F j, Y', $date);
I get December 31, 1969 instead of August 29, 2011. How to get the right date?
Use strtotime on your $date value.
echo date('f j, Y',strtotime($date));
<?php
$date = strtotime($date);
echo date('F j, Y', $date);
?>
To explain...
The function date() is expecting a unix time-stamp (something like 23498034). the function strtotime() takes a normal looking date that a person would make, and converts it to a timestamp. Then you're good to go.

Categories