Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

ACF PLUGIN and data format in italian WordPress

  • SOLVED

Hi, I have this piece of code from the Advanced Custom Field Plugin that returns DATE

my custom field is "data"


<?php
$date = DateTime::createFromFormat('Ymd', get_field('data'));
setlocale(LC_TIME, 'ita', 'it_IT');
echo $date->format('D/d/Y'); ?>


but doesn't works, It returns date in english format like this "Thu/20/Jun",
but I want this "Mar/20/Giu"

anyone could help me ?

Answers (1)

2013-06-12

Arnav Joy answers:

try this

<?php

$date = DateTime::createFromFormat('Ymd', get_field('data'));

setlocale(LC_TIME, 'it_IT');echo strftime("%a/%d/%b", strtotime($date));
?>


Arnav Joy comments:

you can read about it at

http://de3.php.net/manual/en/function.strftime.php


Arnav Joy comments:

you can also try this

<?php
setlocale(LC_TIME, 'it_IT');
echo strftime("%a/%d/%b", get_field('data'));
?>


Manlio Ma comments:

this one returns

Warning: strtotime() expects parameter 1 to be string, object given in


Manlio Ma comments:

the second COde, works, but gives me ever the same date, not create date from custom field :(


Arnav Joy comments:

where are you using the get_field() function? , you have to pass post id if you are not using it inside wordpress loop

i am passing get_the_ID() but you can pass post id here
<?php

setlocale(LC_TIME, 'it_IT');

echo strftime("%a/%d/%b", get_field('data', get_the_ID() ));

?>


Manlio Ma comments:

doesn't work again :(

I use it in single.php and inside the loop in homepage

but with this code works, but in english

<?php
$date = DateTime::createFromFormat('Ymd', get_field('data'));
echo $date->format('D/d/Y');
?>


Arnav Joy comments:

try this

<?php

setlocale(LC_TIME, 'it_IT');

echo strftime("%a/%d/%b", strtotime(get_field('data', get_the_ID() )));

?>


Manlio Ma comments:

WORKS !!! YOU'RE MASTER :)

thank you for the quickly answer!!