- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Compare 2 dates in HUBL
SOLVEOct 2, 2017 12:45 PM
Hi there
I have the following challenge: I want to publish something if the date (Text Field from a module) is bigger than the current date. So I tried this:
{% set publish_date = widget.publish_end_date %}
{% set current_date = local_dt|datetimeformat('%d.%m.%Y') %}
{% if publish_date >= current_date %}
... some HTML Code
{% endif %}
But it doesn't work. Doese anybody has an idea. I checked similar post but nothing helped me.
Thanks a lot,
philip
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Accepted Solutions
Oct 3, 2017 2:53 AM
Where is "widget.publish_end_date" coming from? if you are referencing a custom module you set up on the post page to hold an manually inserted end date for an event then you are not referencing it correctly. It would be "widget_data.publish_end_date.value" .value being the value holder for a text field, .html for richtext, etc.
I would check the output of both date types that you are checking. They both need to be integers in order for you to compare them by size. If both dates correctly referenced, and are correctly converted to integers then comparing their size will do what you need.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Oct 3, 2017 1:27 PM
Look at unixtimestamp at the bottom of this page.
Here is the definition of Unix time time in Wikipedia.
basically it's the number of seconds between 00:00:00 1 January 1970 and a given date, in your case you want the number of seconds between that date and your two dates to compare. convert both to unix time.
Does widget.publish_end_date ouput anything? that seams wierd to me. If you click the sprocket in the to right corner on a page using this template and view developer info fomr the list you will be taken to a page that looks a little like view source. you can use ctrl +f to search for "publish_end_date" and you will find the data for that module which you can use to build the token.
Your using export_to_template_context=True right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content