Keyword

Edit EXTRA FIELD DATE format in specific template

More
10 years 8 months ago #130924 by Bruno
Hi there
would it be possibel to edit the extra field date output for a single (specific) template?

in this case i have the pre-formated date: (eg:) Monday, 21 June 2014
i would like to take out the week day, but only for this template;

i read about this but it was for k2 entire date format, not for extrafield date, nor for a specific template..

any ideas to fix this?

thanks in advance
Bruno

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 8 months ago #130925 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Edit EXTRA FIELD DATE format in specific template
Sorry but the extrafield uses the default format.
You can change the other dates in your template or use a text input instead.

Please Log in or Create an account to join the conversation.

More
10 years 5 days ago - 10 years 5 days ago #143550 by Joe Campbell
Replied by Joe Campbell on topic Edit EXTRA FIELD DATE format in specific template
Hi Bruno,

The solution that I was able to figure out requires Hacking K2 (which I know is not the best thing - so if anyone knows of a solution that does not require a hack - please provide it)

Background:
The K2 Date Extra Field use the K2_DATE_FORMAT_LC to format the date. Which would then require a site-wide Language Override. But what if you only want to format the date for one or a few specific date extra fields, well this is what you need to do.

Open File:
/components/com_k2/models/item.php

Find Code:
$value = JHTML::_('date', $value, JText::_('K2_DATE_FORMAT_LC'), $offset);

Replace With:
$value = JHTML::_('date', $value, JText::_('l d F Y'), $offset);
(this date format simply removes the comma after the day - making it easy to modify later)

Now in your template override file, you can convert the Extra Field Date with the following code:
<?php 
$k2extrafielddate = DateTime::createFromFormat('l d F Y', $this->item->extraFields->ALIASNAME->value);
$new_date_format = $k2extrafielddate ->format('l d F Y'); //specify desired date format
echo $new_date_format;
?>

I hope this helps,

Joe Campbell
Last edit: 10 years 5 days ago by Joe Campbell.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 4 days ago #143572 by Krikor Boghossian
Replied by Krikor Boghossian on topic Edit EXTRA FIELD DATE format in specific template
This looks really nice Joe, Well Done :)

Please Log in or Create an account to join the conversation.

More
10 years 4 days ago #143587 by Joe Campbell
Replied by Joe Campbell on topic Edit EXTRA FIELD DATE format in specific template
Thanks Krikor - it took a lot of trial & error as I am not a coder (proof that you do not have to be a super coder to make a super Joomla website)

Please Log in or Create an account to join the conversation.

More
9 years 11 months ago #143803 by JoomlaWorks
Replied by JoomlaWorks on topic Edit EXTRA FIELD DATE format in specific template
Noted for consideration in the next update. Thank you Joseph.

Please Log in or Create an account to join the conversation.

  • Ronny Van Der Borght
  • Ronny Van Der Borght's Avatar
  • Offline
  • Senior Member
More
7 years 10 months ago #162415 by Ronny Van Der Borght
Replied by Ronny Van Der Borght on topic Edit EXTRA FIELD DATE format in specific template
An other workaround that does not need a core file change could be a str_replace on the extra field value

$newdate = str_replace(array("monday, ","tuesday, ","wednesday, ", "thursday, ","friday, ","saturday, ","sunday, "), "", $this->item->extraFields->Date->value);

This would change 'monday, 1 march 2017' into '1 march2017'

Same can be done for months etc..

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 10 months ago #162424 by Krikor Boghossian
Replied by Krikor Boghossian on topic Edit EXTRA FIELD DATE format in specific template
Thank you Ronny :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum