Home › Forums › General Issues › date picker date display in php 5.2
Hello there,
I would like to thank for this amazing plugin! and ask for a bit of help making the date picker display the date nicely in php 5.2
I have been trying to implement the following code:
$date = DateTime::createFromFormat('Ymd', get_field('date_picker'));
echo $date->format('d-m-Y');
which functioned perfectly in my localhost but didnt work out online in the server.
It gave me the following error message:
Fatal error: Call to undefined method DateTime::createfromformat()
I googled it and it turns out that the createDateFormat is available for PHP versions >= 5.3.0. I checked the server I am working with and I have PHP 5.2.6 only.
Unfortunately, I dont have access to the server to make a php update right now, and I would like to know if its possible to find a workaround in this code to make it work in php 5.2. Unfortunately I am so good in php coding yet. Any help would be highly appreciated.
all the best.
Try this:
list($day, $month, $year) = sscanf('12/04/2010', '%02d/%02d/%04d'); // field value
$datetime = new DateTime("$year-$month-$day"); // your format
echo $datetime->format('r'); // desired format
source: http://stackoverflow.com/questions/2621433/date-create-from-format-equivalent-for-php-5-2-or-lower
Any chance that someone is able to take the code in the first reply, and relate it to the code in the original ticket? I have the same issue (shared server and unable to update the PHP version), so need to be able to output the date in a standard dd/mm/yy format.
Hi @tebbott
Using the strtotime function should work like this:
<?php
$date = get_field('date');
// $date = 19881123 (23/11/1988)
// extract Y,M,D
$y = substr($date, 0, 4);
$m = substr($date, 4, 2);
$d = substr($date, 6, 2);
// create UNIX
$time = strtotime("{$d}-{$m}-{$y}");
// format date
echo date('d/m/Y', $time);
?>
Good luck!
Cheers
E
You’re an inspiration Elliot. Your first class customer service is paralleled only by the amazing plugin you’ve created.
Its individuals like yourself that’re moulding and shaping the internet. A true pioneer.
Many thanks.
I have try thry this but i want to show my date in french like that (25 septembre). So i change the last line like that: echo date(‘F m’, $time);
But the text is in English, how can i set it in french?
Hi @zecka
Here are 2 links to previous threads which demonstrate how you can translate the PHP date time functions!
http://old.support.advancedcustomfields.com/discussion/840/datepicker-language/p1
http://support.advancedcustomfields.com/forums/topic/date-picker-language-front-end/
Thanks
E
The topic ‘date picker date display in php 5.2’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.