Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 2 years, 11 months ago.

Assisted by: Nigel.

Author Posts
July 12, 2022 at 8:22 am #11647663

wen-taoL

I am trying to:
Display date in english in any language
hidden link

Link to a page where the issue can be seen:
hidden link
I expected to see:
Date must be 7 July 15, 202

Instead, I got:
7月 15, 2022

2022-07-12_14-06-04.png
2022-07-12_14-04-48.png
2022-07-12_14-04-22.png
July 13, 2022 at 8:59 am #11656839

Nigel
WPML Supporter since 02/2016

Timezone: Europe/Madrid (GMT+02:00)

Hi there

Can I check, how are you outputting the date?

Simply using the ACF function "the_field" in the theme PHP template? Or some other way?

July 13, 2022 at 11:05 am #11658465

wen-taoL

Sorry I am using get_field

$date = get_field('date');

echo $date;

like this. Also I dont see chat feature on your support. How can i access chat feature for the support?

July 13, 2022 at 12:03 pm #11659241

Nigel
WPML Supporter since 02/2016

Timezone: Europe/Madrid (GMT+02:00)

Chat support is offered when you create a new ticket if there are supporters available to provide it at that time.

Regarding the issue you describe (which is the expected behaviour, dates are output in the format of the current locale), the ACF date field stores the field value in wp_postmeta in the format "yyyymmdd" (e.g. for today that would be "20220713").

When you use the function get_field it returns the formatted value based upon the current locale (and the format you specify in the ACF settings for the field).

Note this has nothing to do with WPML per se, you would see the same if you disabled WPML plugins and changed the site language and checked the results on the front end. For each language the date would be formatted according to the locale.

If you want something different than this standard behaviour you will need some custom code to generate the date in the required format, ignoring the current locale.

You will want to retrieve the unformatted value of the date field (so the $format_value parameter should be set to false: hidden link).

Convert that to a timestamp with strtotime (hidden link).

Then format that without making any allowance for the locale, with the date function (hidden link).

Your code should probably look something like this (not sure if you have the post ID already available):

global $post;
$date = get_field('date', $post->ID, false);
$date_timestamp = strtotime( $date );
$date_formatted = date( "F j, Y", $date_timestamp );

echo $date_formatted;