I have a custom field (date picker) with MetaBox and I am trying to display on the front end.
Dynamic data brings this in and displays in 2022-07-08 format but I would like May 8, 2022.
I have tried adding a filter (the dynamic data filter docs do not show any examples) but i have tried {date:F j, Y} and {date:MMM dd, YYYY) and other variations but none work. date is the name of the custom field
How can I change the output of the dynamic data date?
Did you get this figured out? I was having the same issue, and couldn’t get the date filter to work, so I ended up using a code block instead. Bizarrely, Metabox seems to return the date as a string, so I had to convert it to a date format first, before applying the date formatting.
I came across this topic and have the same problem. Formatting the date picker only works for the backend input field. In the database it’s still stored as Y-m-d .Whatever I try I can’t get it to work.
Also I tried the code inside a codebox, but it’s all a bit beyond me how to properly implement such a code snippet.
Has anybody found a way to get this to work?
UPDATE::
Oops, I did not executed to code (didn’t know I had to enable this first) However it’s works like a charm… Still figuring out how to get it outputted in Dutch language though.
Hi,
I’m trying to adjust the code to output a translated version of the date. In the end I’m trying to make a date box for an event listing. Anybody out there that has proper coding skills and knows what I’m doing wrong here?
<?php
/* get the date */
$input = rwmb_get_value('datum_optreden');
$date = strtotime($input);
/* get the language */
$lang = get_locale();
$timezone = wp_timezone_string();
/* translation */
$fmt = new IntlDateFormatter(
$lang,
IntlDateFormatter::FULL,
IntlDateFormatter::MEDIUM,
$timezone,
IntlDateFormatter::GREGORIAN
);
/* trim the date */
$trimmed_date = date('j M',$date);
$output = $fmt->format ($trimmed_date);
echo $output;
?>
It’s not the most ideal solution. It would be great if Bricks had a filter etc for converting a timestamp then most problems could be solved by just saving the date as a timestamp.
@timmse is it possible to filter a timestamp in Bricks or can we get a filter for this?
Since I’d like to create a datebox with the day number on top and the month abbreviation below, I’ll try saving it as time stamp. And output it with code.
However, the meta query ( greater or equal than current date) doesn’t seem to work then. For meta value I use {current_date:U} , which should output the current date in timestamp format.
Maybe another option is use j M as date format and trim the given string to only output the desired part of the string.
I would still have the translation problem, so timestamp is a better option still.
Also, wouldn’t it be possible to use the date filter from bricks if the date was actually stored as a date instead of a string in the database?
instead of creating a new post about this topic, i thought it was better to reply here.
i am in a very similar situation, and i’m still struggling despite all these posts.
i’ve set the metabox date picker to dd MM yy, so it should output 01 August 20023. it was actually working on the frontend.
when sorting the posts using the meta value of the id, 01 September 2023 comes before 02 August 2022, because of the first digits (days), and of course this is the main issue. i thought it was saving dates using YYYY-MM-DD.
then something really odd happened.
in admin columns pro i was not able to see the date in the column i’ve set, so i checked the option to edit inline, and then i was able to enter the dates directly in the column. it now uses d m Y for displaying the dates, but making the column order incredibly correct because it reads, somewhere, YYYY-MM-DD. that’s good enough.
this created a problem somewhere: from that point, in the frontend, the output is YYYY-MM-DD even if i did not edit the date format. no matter what format i chose in the date picker field, it seems that the admin columns pro is making some mess. the column order is working, the post sorting is also working, but i need dd MM yy.