0

The database has a string which is a date in the format of dd/mm/yyyy (13/03/2014). No, it has not been saved to the database as a proper date/time.

With Low Replace we are able to change the format of this to yyyy/mmm/dd

{exp:low_replace find="/(\d{2})\/(\d{2})\/(\d{4})/" replace="$3/$2/$1" regex="yes"}
  13/03/2014
{/exp:low_replace}

Is it possible to apply Nice Date to the date after Replace has done it's thing as nice date won't work with dd/mm/yyyy? Or do we need to use something like Stash to create a variable for Nice date to work with once Replace has converted it?

2
  • Are you able to change the values of the date in the DB? You could change the format to dd-mm-yyyy with one query, which would remove the need of using Low Replace altogether. – Low Mar 4 '14 at 7:58
  • Thanks Low, I think that will probably be what we end up doing. Not sure how to close this questions now? – Mike Dexter Mar 4 '14 at 8:18
0

I'd recommend changing the value of the date field to dd-mm-yyyy so you don't need to use Low Replace, and instead can use the value directly into Low Nice Date. The query would look something like this:

UPDATE exp_channel_data SET field_id_X = REPLACE(field_id_X, '/', '-');

Where X is the field ID in question.

0
0

You might have luck with this...

{exp:low_nice_date date="{exp:low_replace find="/(\d{2})\/(\d{2})\/(\d{4})/" replace="$3/$2/$1" regex="yes"}13/03/2014{/exp:low_replace}" format="%F %Y" parse="inward"}

If that works, consider moving the low_replace into a snippet so it's easier to read

{exp:low_nice_date date="{sn_fixed-date}" format="%F %Y" parse="inward"}

Hope that helps!

1
  • Hi Andrew. Thanks for the advice. Looks like that doesn't work. – Mike Dexter Mar 3 '14 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.