Store cb_date_field_A as formatted date in cb_date_field_B

6 months 4 weeks ago #328800 by 3by400Inc
We have a cb field storing a date value like yyyy-mm-dd that we use for several triggers but I'd also like to store the same date value in a second cb field in a nicer format like j F Y so we can map it to Moodle and print it on PDF certificates.

I've setup a Code field using the following code that accurately grabs the cb_date_field_A and displays it in cb_date_field_B, but the issue is its not actually storing the value in the database, its only displaying it on the backend and frontend user profile. In fact, it doesn't appear that Code fields actually create a table column at all. Is there a way I can accomplish the same goal but have a stored value in the DB that I can then map over to Moodle?
$datetime = new DateTime();
if ($user->cb_expdate_3 == "0000-00-00" || NULL) return NULL;
$prettydatetime = new DateTime($user->cb_expdate_3);
return $prettydatetime->format('j F Y');

Please Log in to join the conversation.

6 months 4 weeks ago #328806 by krileon
Date, Datetime, and Time fields support custom display formats. You should be able to just change the format directly in your field under Parameters > Display. Next use [FIELD_NAME] when you want SQL formatted (0000-00-00 00:00:00) and use [cb:userfield field="FIELD_NAME" /] when you want it display formatted.

You are correct that Code fields have no storage at all. They simply take your PHP and display it as a field value. They can still be substituted in, but they cannot be queried for.

Is there a way I can accomplish the same goal but have a stored value in the DB that I can then map over to Moodle?

Is there a reason it needs to be stored in the database? You should be able to push data to Moodle using CB Auto Action using substitutions to get field values.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.148 seconds

Facebook Twitter LinkedIn