How ot customize the date format in products comments

  • Posts: 224
  • Thank you received: 8
5 years 11 months ago #292976

Hello,
I see that the date format in products comments is handled by the language string
HIKASHOP_EXTENDED_DATE_FORMAT="%d.%m.%Y - %H:%M"

I woudl like a different format (like 20 May 2018), but if I change that language string this will affect the date format on orders/invoices etc... whcih instead should stay %d.%m.%Y - %H:%M

so how to do this?
in vote / listing.php file I see this code

<td colspan="8"><?php
			$voteClass = hikashop_get('class.vote');
			$vote = $voteClass->get($elt->vote_id);
			echo hikashop_getDate($vote->vote_date);
		?></td>

could you suggest maybe how to edit it in order to pull a different language string?

thank you!

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

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
5 years 11 months ago #292998

Hi,

You can just change the line:
echo hikashop_getDate($vote->vote_date);
to:
echo hikashop_getDate($vote->vote_date, '%d.%m.%Y - %H:%M');
and replace %d.%m.%Y - %H:%M by the format you want:
us2.php.net/strftime/

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

  • Posts: 224
  • Thank you received: 8
5 years 11 months ago #293011

Thank you,
I tried this but it's not working unfortunately.
I inserted

<tr>
		<td colspan="8"><?php
			$voteClass = hikashop_get('class.vote');
			$vote = $voteClass->get($elt->vote_id);
			echo hikashop_getDate($vote->vote_date, '%d %B %Y');
		?></td>
	</tr>

should show 22 May 2018
but it still shows 22.05.2018

I tried to insert some new comments to see if this would change only in the new ones,
I have also verified that the vote / listing.php is rendering the changes correctly, tried to add a test paragraph and it shows

so what could this be?

Attachments:

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

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
5 years 11 months ago #293015

Hi,

Make sure that you're editing the correct view file wih the "Display view files" setting of the HikaShop configuration.
It should indeed be vote/listing.php
Make sure that you're editing it for the correct template.

Also, note that the %d %B %Y format is a default format and thus if you use that, it will automatically use the translation key:
HIKASHOP_DATE_FORMAT="%d %B %Y"
So either you change that translation key, or instead of the format, you use a new translation key and you enter the format for that translation key in your translation override so that the system can use it.

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

  • Posts: 224
  • Thank you received: 8
5 years 11 months ago #293091

Ok, this is really strange...

so I inserted a language string

echo hikashop_getDate($vote->vote_date, JText::_('HIKASHOP_DATE_VOTE'));
and in my language file
HIKASHOP_DATE_VOTE="%d %B %Y"
result is always the same: 22.05.2018
these are all other language strings I have on file
HIKASHOP_DATE_FORMAT="%d.%m.%Y"
HIKASHOP_DATE_VOTE="%d %B %Y"
HIKASHOP_EXTENDED_DATE_FORMAT="%d.%m.%Y - %H:%M"
the vote / listing.php si definitely the right one, If I insert some text I can see it on frontend, also
when I change
echo hikashop_getDate($vote->vote_date, JText::_('HIKASHOP_DATE_VOTE'));
to
echo hikashop_getDate($vote->vote_date, JText::_('HIKASHOP_EXTENDED_DATE_FORMAT'));
the date indeed changed to: 22.05.2018 - 10:23

but as soon as I change it back to
echo hikashop_getDate($vote->vote_date, JText::_('HIKASHOP_DATE_VOTE'));
it becomes again: 22.05.2018

so I am confused here...because if I change the language string to
HIKASHOP_DATE_VOTE="%Y"
then I correctly see just the year
but as soon as I change it to
HIKASHOP_DATE_VOTE="%d %B %Y"

I see: 22.05.2018
while it should be: 22 May 2018

this is truly a mistery to me!

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

  • Posts: 15
  • Thank you received: 0
  • Hikashop Essential
5 years 11 months ago #293099

I trying to cange date formats at the moment.You could try the date format as:
‘d.M.y – h.i’

d = day as 2 digits
M = month as 3 letters i.e. Jan
F = month in full i.e. January
y = year as 2 digits i.e. 18
Y = year as 4 digits i.e. 2018
h = hour in 12 hour format
I = minutes

This works for me but don't know if its the best way.

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

  • Posts: 224
  • Thank you received: 8
5 years 11 months ago #293105

Thanks Malcom but I need this format to work "%d %B %Y"

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

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
5 years 11 months ago #293093

Hi,

No, you need to pass the translation key, not the text.
So the code should be for example:

echo hikashop_getDate($vote->vote_date, 'HIKASHOP_DATE_VOTE');

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

  • Posts: 224
  • Thank you received: 8
5 years 11 months ago #293118

mmmh..

if I insert this

echo hikashop_getDate($vote->vote_date, 'HIKASHOP_DATE_VOTE');
I get this
%02 %482 %2018

if I insert this
echo hikashop_getDate($vote->vote_date, JText::_('HIKASHOP_DATE_VOTE'));
I get this
02.04.2018

while it should be
2 Apr 2018

because the language string is
HIKASHOP_DATE_VOTE="%d %B %Y"

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

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
5 years 11 months ago #293120

Hi,

I don't see why it would do that.
Then simply use instead the date function of PHP with the format you want:
php.net/manual/fr/function.date.php

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

  • Posts: 224
  • Thank you received: 8
5 years 10 months ago #293149

Yes, this is quite misterious to me too...
I have already tried
echo hikashop_getDate($vote->vote_date, '%d %B %Y');
see third reply on this same post

It still renders 02.04.2018 and not 2 Apr 2018

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

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
5 years 10 months ago #293162

Then use the date function instead of hikashop_getDate as I said in my previous message.

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

  • Posts: 224
  • Thank you received: 8
5 years 10 months ago #293217

Thank you for your patience Nicola,
I am not a developer and I don't always understand fully what you mean :unsure:

This finally did the trick and now the votes date is showing correctly

echo hikashop_getDate($vote->vote_date, 'j F Y');

thanks again!

Last edit: 5 years 10 months ago by oloccina.

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

Time to create page: 0.089 seconds
Powered by Kunena Forum