MetaBox Date Picker format date

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?

Hi,

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.

<?php
  $input = rwmb_get_value('date');
  $date = strtotime($input);
  echo date('D, jS F Y', $date);
?>

Hope that helps.

Did someone figure it out how to change it via dynamic data?

Hi there.

I think I found the post You all looking for:

Just change the format as You wish. Important : select the date / time in You custom field again
and safe. Works for me! :slight_smile:

1 Like

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;

?>

You should use date_i18n() function for this.

1 Like

you just need to enter in the custom field save format the format you wish to display it as

image

gives

image

You can also save the date as a timestamp but you will then need to make a function to convert to what format you wish.

You can make a date format using - https://www.php.net/manual/en/datetime.format.php

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?

1 Like

Thanks for your help with 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?

OK , I found a solution…
The format stays Y-m-d , which makes it work with the meta query filter.

The code element has the following code (Thanks Yankiara for the suggestion)

<?php

	/* get the date */
  $input = rwmb_get_value('datum_optreden');
  $date = strtotime($input);
	$dag_nr = date_i18n('j', $date);
	$maand_afk = date_i18n('M', $date);
?>
<div class="dag_nr">
  <?php	echo $dag_nr;	?>
</div>
<div class="maand_afk">
  <?php	echo $maand_afk;	?>
</div>
<?php $months = array( 'januari', 'februari', 'maart', 'april', 'mei', 'juni', 'juli ', 'augustus', 'september', 'oktober', 'november', 'december', ); $input = rwmb_get_value('re_datum'); $date = strtotime($input); $cmonth = $months[(date_i18n('n', $date)-1)]; $cday = date_i18n('j', $date); $cyear = date_i18n('Y', $date); echo "Datum {$cday} {$cmonth} {$cyear}"; ?>

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.

https://api.jqueryui.com/datepicker/#utility-formatDate

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.

i need to clean all of that.

  • i need to be able to see the date in the column
  • but avoid inline editing because it creates problems with the actual frontend display
  • and i surely need to sort the posts using YYYY-MM-DD and display them as dd MM yy.

anyone have a solution?