time-sensitive CTA links

Hi - I don’t think this is probably the best place to post this so if you have other suggestions, let me know. But I had to start somewhere…

I’m a web developer working for a client using Hubspot. He has some pages with CTA links. He’d like the links to send users to one URL during work hours and another during non-work hours.

Any suggestions on how to accomplish this? The current URL has all kinds of data beyond just the page URL, do I need to include that somehow?

Thanks for any input.

Steve Ralston

Hi @SRalston05,

As far as I know, this would not be possible by editing the CTA itself and would require some conditional logic to show the desired CTA based on the time period.

HubL has a variable called local_dt. Per the documentation:

A datetime object of the current time in the time zone defined in your Report Settings. Usage of this variable will disable page caching in order to return the current time. May hurt page performance. Use JavaScript instead to get current date and time in a cacheable way.

You could use this variable to extract the current hour and compare it to a range to see if it falls within the business hours.

Below example checks whether the current hour is between 9am and 5pm (it uses the 24 hour clock here, so the 17 = 5pm) and would show the CTA for business hours if yes, then the non-business hours CTA if current hour is outside of business hours:

{% set current_hour = local_dt|datetimeformat('%H')|int %}

{% if current_hour >= 9 && current_hour < 17 %}
 CTA 1 HERE (FOR BUSINESS HOURS)
{% else %}
 CTA 2 HERE (FOR NON-BUSINESS HOURS)
{% endif %}

To answer the question about the URLs, you don’t need to do anything special there - the code for the CTA itself should include the URL parameters on the destination page.

Hope this helps!

A good way to create time-sensitive CTA links in HubSpot is by using URL parameters combined with workflows. You could create a property with an expiration date, and build dynamic URLs or smart CTAs that change behavior once the expiration date passes. Another option would be using HubL in custom-coded email templates to automatically update or disable links based on a set time condition.