How to apply date formatting to elements loaded in form intro?

Status
Not open for further replies.
I am calling two elements in a form's intro: MEMBERSHIP DATES: {tablename___from_date} - {tablename___to_date}. The elements load, but the formatting includes time. I only need month, day and year. Is there a way to format the date stamp so that it displays without the time?

Joomla 3.3.1
Fabrik 3.1.1
 
the only way I could think of would be to create a custom form template which with some PHP formatted the dates in the format you needed. If your placeholder date is in the format 'yyyy-mm-dd hh:mm:ss' then this code should work:

PHP:
<?php
$from = JFactory::getDate('{tablename___from_date}')->format('yyyy-mm-dd');
$to = JFactory::getDate('{tablename___to_date}')->format('yyyy-mm-dd');
?>
 
<p>
This is at the top of your custom form template and serves as the intro text; You can included a date with <?php echo $from; ?> and <?php echo $to; ?>
</p>
 
hmm perhaps you need the raw version of the date:

PHP:
<?php
$from = JFactory::getDate('{tablename___from_date_raw}')->format('yyyy-mm-dd');
$to = JFactory::getDate('{tablename___to_date_raw}')->format('yyyy-mm-dd');
?>
 
<p>
This is at the top of your custom form template and serves as the intro text; You can included a date with <?php echo $from; ?> and <?php echo $to; ?>
</p>
 
Check with e.g.
Code:
$from ='{tablename___from_date_raw}';
$to ='{tablename___to_date_raw}';
var_dump($from,$to);exit;
what you get (maybe arrays?)
 
  • Like
Reactions: rob
Yes, confirmed.
Seems placeholders are replaced only AFTER the php code has been run (which is hard to detect because if you do
var_dump '{aaa_bbb}'; (without an exit; ) this will be echoed as {aaa_bbb} and then afterwards replaced to e.g. 2014-08-08 14:00. So you'll think it is correct as long as you don't count the characters).

You can access your elements with
$to = $this->groups['Test2']->elements['to_date']->element_raw;
(I assume there's a better method but I don't know)
 
  • Like
Reactions: rob
Thanks for this:

$to = $this->groups['Test2']->elements['to_date']->element_raw;

While it gets the dates to return, the formatting is still not resolved, as it returns 2009-04-14 06:00:00 instead of 2009-04-14 or even better 04-14-2009.
 
Now you have to add the date formatting, try

$to = JFactory::getDate($to)->format('dd-mm-yyyy');

(maybe the format is 'd-m-Y', I never used this)
 
Perfect! This is what I ultimately went with:

Code:
<?php
$fromget = $this->groups['xxx']->elements['from_date']->element_raw;
$toget = $this->groups['xxx']->elements['to_date']->element_raw;
$from = JFactory::getDate($fromget)->format('m-d-Y');
$to = JFactory::getDate($toget)->format('m-d-Y');
?>
<table style="width:15%;line-height:25px;font-size:140%;">
  <tr>
    <td>Membership Start:</td>
    <td><?php echo $from; ?></td>       
   
  </tr>
  <tr>
    <td>Membership End:</td>
    <td><?php echo $to; ?></td>       
   
  </tr>
  </table>
 
</body>
</html>
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top