I am using the following code in a template:
<?php echo $articleItem->date('M Y');
if ($articleItem->dateUntil()->isNotEmpty()) :
echo ' - ' . $articleItem->dateUntil('M Y');
endif; ?>
It outputs as:
Jan 2006 - 2010-12-31
The first date seems correct, the second date is not in the right format. Both have the same type in the blueprint:
date:
label: Date
type: date
format: MM/DD/YYYY
dateUntil:
label: Date Until
type: date
format: MM/DD/YYYY
If I output them as raw info, one is a timecode and the other is a date (2010-12-31).
I am really confused. Both should be the same. I canβ work out why they are different. Any pointers greatly appreciated.
Regards
Mike
The date()
method is special. It allows the format string while other methods do not.
You can output the dateUntil
field with your custom format using this code:
echo ' - ' . $articleItem->date('M Y', 'dateUntil');
The second parameter of date()
defines the field to use.
PS: Please post your code using Markdown code blocks in the future. They use three backticks at the beginning and end of the code in separate lines. I have changed it for you above.
1 Like
Thanks Lukas
Much appreciated. It looks like I was lucky with my first one, getting the the date format to work that is (my field being called date and β¦)
I will also add code using three back ticks. Thanks for amending my original post for me.
[insert smiley face]
Regards
Mike