Skip to Content Skip to Menu

🌟 CB Editor Assistant 1.0.0 is here! Discover our new AI Joomla Plugin that wrote its story! (and this banner!)
Start at just $12.50/month* or 💸 save 30% with our 🛍️ Intro Black Friday Offer for a lifetime*

Auto Actions calculations with date

  • Abmago
  • Abmago
  • OFFLINE
  • Posts: 47
  • Thanks: 6
  • Karma: 0
4 years 7 months ago #317711 by Abmago
Auto Actions calculations with date was created by Abmago
I need to calculate with date numbers. This makes it possible to calculate age, but I also need it for something else. However, Auto Actions can only calculate with integer. And dates are not integer.

For example: I can calculate the current year as follows: [cb:parse function="date" date-format="Y"

But how can I convert the result into integer? Other wise, I cannot calculate with it.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48551
  • Thanks: 8291
  • Karma: 1445
4 years 7 months ago #317723 by krileon
Replied by krileon on topic Auto Actions calculations with date
The Date format function formats the supplied datetime string to whatever format you're wanting. The Time format function lets you manipulate a date. For just returning the current year for example you'd use CBs standard date substitution for that. For example the below will give you the current year as an integer.

[cb:date format="Y" /]

You can find this substitution in our substitution tutorial below.

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

If you want to get the year from an existing date value you'd use the Date format function for that though. Example as follows.

[cb:parse function="date" date-format="Y" time="false"]DATE_HERE[/cb:parse]


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 or Create an account to join the conversation.

  • Abmago
  • Abmago
  • OFFLINE
  • Posts: 47
  • Thanks: 6
  • Karma: 0
4 years 7 months ago #317724 by Abmago
Replied by Abmago on topic Auto Actions calculations with date
I have already made a field (cb_dateyear) with code

[cb:date format="Y" /]

This looks like an integer, but I cannot make calculations with this field in CB Auto Actions...

What 'type' does this field need? When I choose 'integer', there is no value shown (at least in my profile) and there is also no calculation possible. When I choose 'custom HTML' the right value is shown in the profile, but this value not recognized as valid input in CB Auto Actions.

This simple calculation does not work:

[cb:parse function="math"] [cb_dateyear] - [cb_yearofbirth][/cb:parse]

The field [cb_yearofbirth] is an integer field, that the user had to choose. This works fine. When I subsitute [cb_dateyear] with the number 2020, the result in the calculation is good...

So there is something wrong with the field cb_dateyear and I don't know what.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48551
  • Thanks: 8291
  • Karma: 1445
4 years 7 months ago #317727 by krileon
Replied by krileon on topic Auto Actions calculations with date
Do you even need to use cb_dateyear? You should be able to just directly put [cb:date format="Y" /] in your math format function usage.


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 or Create an account to join the conversation.

  • Abmago
  • Abmago
  • OFFLINE
  • Posts: 47
  • Thanks: 6
  • Karma: 0
4 years 7 months ago #317739 by Abmago
Replied by Abmago on topic Auto Actions calculations with date
Yes, this helps! Thank you very much. I hope that I can also use this solutions in the more difficult calculation I need. For now I can go on.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48551
  • Thanks: 8291
  • Karma: 1445
4 years 7 months ago #317763 by krileon
Replied by krileon on topic Auto Actions calculations with date
You could try using the clean function which will typecast for you if you run into this issue in the future. Example as follows.

[cb:parse function="clean" method="int"][cb_dateyear][/cb:parse]

That should guarantee it's cast to an integer.


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 or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum