Help with Smarty dateformat modifier - change to dd/mm/yyyy
pevans11 opened this issue · 5 comments
Hello.
Forgive me, I am not overly technical - I hope the below makes sense to you and I am in the right place!
I am using Formstack and they use smarty modifiers to mail merge their form fields onto MS Word Documents.
I have a date field {$contractstartdate} that is showing the date as per how it was entered on the in-take formstack form. The format is dd/mm/YYYY (e.g 20/05/2024) however I would like this to appear in this: Monday, 20 May, 2024.
I am aware there of the {$contractstartdate|date_format:"%A, %B %e, %Y"} smarty modifier that changes dates into words. However my problem is, the modifier is confusing the date for the month, and vise versa - probably because it is referencing a different date format.
Is there a modifier {$..} that reads the date as dd/mm/yyyy (instead of mm/dd/yyyy which I think it is currently doing?) and then also change that to this format: Monday, 5 May, 2024.
If so, please can you kindly type it out for me so I can copy and paste into my word document?
I've come across this Smarty page on dates, but I do not understand it: https://smarty-php.github.io/smarty/stable/designers/language-modifiers/language-modifier-date-format/#basic-usage
I suspect this is not possible, but I'd appreciate your time in advance if you could confirm for me?
Many thanks.
Paul
Is $contractstartdate
a string, or a integer unixtime?
A string a believe. It is simply showing the contract start date value entered on the original Formstack form in dd/mm/yyyy format for the mail merge. Does that help/make sense?
The problem here is that the xx/xx/xxxx format signals that it is an American date, ie mm/dd/yyyy. Passing it as xx-xx-xxxx might "fix" it.
It is better to do this outside of the Smarty template.
The date_format()
modifier is going to expect a unixtime integer, that's probably why you're getting weird results. Try converting it to a unixtime with strtotime()
in PHP and passing that to your template instead.
@scottchiefbaker that won't help here. Smarty internally uses strtotime
if it has no other way of determining the format the a string passed to date_format
. So the underlying problem here is that strotime does not recognize dd/mm/yyyy. But this is not a bug, it's a feature.