I use ACF alongside views and here's my problem :
I have a date picker in the back-end to store a date with ACF. The value is stored as yymmdd.
When I use views to show a list a CPT with the upcoming date, the output is for example : 20180928.
Here's the shortcode generated in views :
[wpv-post-field name='gestion_groupe_0_date_debut']
Is there a way to output it in a d F Y way?
If I embeded the field in a php template I can use the echo date_i18n function and define format...
"20180928" means that date is stored as a Timestamp, just like Types Toolset's Date field as well.
However, our shortcode for our own date field can convert this to a human readable time, while when the data comes directly from the database (I see you use the post fields shortcode to display this 3rd party field) then the data is not converted, because we do not know it is a date field.
So you can, for example, get that field's value in a custom shortcode, and convert it to whatever you like, then return this and register the ShortCode in Toolset > Settings > Front End Content > Third-party shortcode arguments
Then you can use your Custom ShortCode in the View.
I have a similar example here, which will show you how to convert the actual field value:
$acf_field_value = get_post_meta( $post_id, 'your_acf_field', true );//get posts' Date field value (will retrun a timestamp)
$converted_acf_field_value = gmdate("m-d-Y", $acf_field_value);//convert timestamp to m-d-y for output
That ShortCode can be used to display this Date Field as a humanly readable date, anywhere you have access to that data and an existing post, of course.
Thanks Beda, but I must misread something or miss something but it doesn't work.
If created a shortcode :
function date_convert_func(){
$acf_field_value = get_sub_field('date_debut');
$converted_acf_field_value = gmdate("j F Y", $acf_field_value);//convert timestamp to m-d-y for output
}
add_shortcode('date_convert', 'date_convert_func');
Then I registred it in tootset (see image)
At last, I tried to output it in views :
[wpv-post-field id="[date_convert]"]
Well - It looks like my colleague Beda has missed something here.
The value you are getting is a date string - not a timestamp.
Would you mind to share problem URL and access details with information where you want to display this date and tell me in which format you want to display it?
I have set the next reply to private which means only you and I have access to it.
Instead of starting a new thread, I will update this one as the solution doesn't solve entirely my problem :
The shortcode provided tranform the unix timestamp in a readable format. But, if there's no date, it output the date of the present day (as shown in image)....