Skip to Content Skip to Menu

CB Query for calculating difference between dates

6 years 8 months ago #301754 by Andrew Dunn
Hi
I am using CB 2 with the query plugin and content plugin. I am trying to do a substitution that shows content to people who have been attending classes for longer than x days.

In order to work out x days I have a field called cb_classstart which is a date. I would like to have a field called cb_daysdiffquery that calculates the number of days between the start date and the current date however I am not sure of the calculation please and I was hoping you could help me to achieve this.

My plan is to then use a substitution that is something like


[cb:if cb_daysdiffquery > 1]Content I want to show[cb:else]This content is not available yet and will be available after 1 day.[/cb:else][/cb:if]

I look forward to hearing from you.

Thank you
Andrew

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48444
  • Thanks: 8279
  • Karma: 1443
6 years 8 months ago #301767 by krileon
See the below MYSQL function documentation. Please understand we're not here to teach you coding or provide custom code on demand.

dev.mysql.com/doc/refman/5.6/en/functions.html

Specifically you'll need to utilize date functions.

dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html

You can probably just do a SELECT of the datediff of the 2 dates then condition against the datediff value in your IF substitution.

dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_datediff


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