Format a date value read from a database

pharms 29 Nov, 2014
Hi

Using the "DB Read" action, I'm able to read a date value from a DB record based on the value of a GET variable passed in the form URL, it's returned in the format "2014-10-26 00:00:00".

I can use the value returned to populate a form field (a text box) by naming the form field the same name as the DB field that contains the date read. So far so good.

What I'd like to do is display the date returned as say "Sunday, October 26, 2014" instead of the raw DB format.

I tried setting a date_format command in the field list of the DB Read action "DATE_FORMAT(study_date,'%W, %M %e, %Y) AS date" but it didn't work. study_date is the DB field name.

Any ideas how I could do this? I have no php experience.

Cheers
Max_admin 29 Nov, 2014
Answer
1 Likes
Hi pharms,

You can change the value using php in a "custom code" action before the "html" action:

<?php
$form->data["field_name"] = date("format here", strtotime($form->data["field_name"]));


Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
pharms 30 Nov, 2014
Thanks! problem solved. I used this code:

<?php
$form->data["study_date"] = date("l, F j, Y", strtotime($form->data["study_date"]));
php?>

Peter
This topic is locked and no more replies can be posted.