Skip to Content Skip to Menu

[SOLVED] CB date format issue in code auto action

7 years 1 month ago - 7 years 1 month ago #297268 by soportemarketing
[SOLVED] CB date format issue in code auto action was created by soportemarketing
Hello:

I've a CB field, with date Y-m-d format in comprofiler table, and I want to get it in a auto action code for sinchronyze another database table, where field is varchar(255). Eg:

cb_fechanacimiento, value 1960-01-25

When I do:

$fechanac1=[cb_fechanacimiento];
$fechanac2=[cb:userdata field="cb_fechanacimiento" /];

The two variables are converted to 1934 integer. But, when I put this in a update query:

,$db->quoteName('fechanacimiento') . ' = ' . $db->quote('[cb_fechanacimiento]'),

value goes right to 1960-01-25.

What I want is to get and convert 1960-01-25 to string 25/01/1960 for including this in the query, but I can't

Thanks for your help.

Regards.
Last edit: 7 years 1 month ago by krileon. Reason: Added [SOLVED] tag to subject

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48444
  • Thanks: 8279
  • Karma: 1443
7 years 1 month ago #297271 by krileon
Replied by krileon on topic CB date format issue in code auto action
The [FIELD_NAME] substitutions are raw database values. They have no formatting or field behavior applied to them. If you want it to display the same way it does on profile you'll need to use [cb:userfield field="FIELD_NAME" /]. See the substitution tutorial below for further usage information.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18353-using-substitutions-throughout-cb

Please also note you need to treat substitutions as strings. When defining your variables be sure to surround your substitutions with quotes.


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.
The following user(s) said Thank You: soportemarketing

Please Log in or Create an account to join the conversation.

7 years 1 month ago #297284 by soportemarketing
Replied by soportemarketing on topic CB date format issue in code auto action
It was the quote. Now it works as I expected:

$fechanac1='';
$fechaconvertida='';
[cb:if cb_fechanacimiento!=""]
$fechanac1='[cb_fechanacimiento]';
$fechaconvertida= date("d/m/Y", strtotime($fechanac1));
[/cb:if]

But in the auto action, this $fechanac3='[cb:userfield field="cb_fechanacimiento" /]'; results in a empty string, I don't know why, but every way the issue is solved.

Thanks!!!

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum