Stop! There's a better way.
This snippet is available as a plugin with Gravity Perks, a suite of over 47 premium Gravity Forms plugins!
You’re probably familiar with Gravity Forms conditional logic. That awesome feature that allows you to show or hide fields depending a set of custom conditions. One feature that isn’t yet support is date-based conditions. Or is it?
This method will allow you to show or hide any field based on a date. You can configure it to show/hide if that date has passed, has not passed or if you are currently on that date.
This tutorial is based on the following example. You are selling tickets to a conference. Tickets sold a week before the conference are $10. Tickets sold within a week of the conference are $15. Let’s dig in!
1. The Code
Copy and paste the above snippet into your theme’s functions.php file. This code enables you to populate a field on your form with the current date and time in the form of a UNIX timestamp.
It isn’t super important that you know what a UNIX timestamp is (the number of seconds since January 1, 1970) but it is important to understand that a timestamp is an integer. No weird date formatting just a really big number. For example, this post was published on March 1, 2013. The time stamp for this date is 1362117600.
Gravity Forms conditional logic can’t work with formatted dates but by converting the date into a number we can let Gravity Forms handle the rest.
2. Setting Up Time Stamp Field
Our timestamp snippet doesn’t do much on it’s own. We need to tell it which field to populate with the timestamp. Go ahead and open any form to which you would like to add this functionality and follow these steps:
- Add a new Hidden field and label it “Timestamp”
- Click on the “Advanced” tab to view the field’s advanced settings.
- Check the checkbox labeled “Allow Field to be Populated Dynamically”.
- Enabling the “Allow Field to be Populated Dynamically” option will reveal the “Parameter Name” input. Add this value
timestamp
.
Awesome! Now this field is configured to be dynamically populated with the current timestamp any time the form is viewed.

3. Setting Up Conditional Field
Now it’s time for the fun part!
- Create another field that you would like to which you would like to apply the date-based conditional logic.
- Click on the “Advanced” tab to access the field’s advanced settings.
- Check the “Enable Conditional Logic” checkbox.
- Select the “Timestamp” field from the first drop down.
- Select “less than” or “greater than” from the operator drop down depending on your intent (more details below).
- Enter the timestamp for the date this condition is based on (more details below).
For our working example, we will have two product fields. One with the early bird pricing (any time a week before the event) and another for regular pricing (any time within a week of the event).
The event is on March 18, 2013. We want the pricing to be dependent on a date one week before the event, so March 8, 2013 is our “conditional date”. The timestamp for this date (set to midnight) is 1362700800. Based on that conditional date, here is how each field’s conditional logic would be configured:


Should I use “less than”, “greater than”, or “is”?
If the field should show/hide if the current date is before the conditional date, you will want to use the “less than” operator.
If the field should show/hide if the current date is after the conditional date, you will want to use the “greater than” operator. You’ll note in the example, the regular pricing has an extra “is” clause. Without this, there would be one second at midnight on the conditional date that neither pricing field would display.
If the field should show/hide between two dates, you will need to create two conditions and use the “greater than” for the starting date condition and “less than” for the ending date condition.
How do I get a timestamp for my conditional date?
The conditional date will also need to be in the UNIX timestamp format. Use this online UNIX timestamp converter to convert the date you want to base your show/hide condition on to a timestamp. Once you have your timestamp, enter it into the last input on the condition row.
Did this resource help you do something awesome with Gravity Forms?
Then you'll absolutely love Gravity Perks; a suite of 47+ essential add-ons for Gravity Forms with support you can count on.
Can you send notifications based on a date? For example, send out the customer notification 2 weeks prior to a date field. I want to be able to send a one-time payment reminder to new customers 2 weeks prior to their very first bill being due. In the form I would put a “Due Date” field and the system would send out the desired Notification 2 weeks prior to that date.
Hi Chris, we actually just did a freelance project and have a plugin in-the-works for this. It’s not ready yet but it’ll be part of the Gravity Perks package when it is.
Hi! I’m wondering if it’s possible with GP Conditional Logic Dates to use this with Confirmations? Basically I want to be able to set up confirmations that send users to various pages depending on the date selected but of course dates are not available in conditional logic in the Confirmations section.
Hi Dave, I think I answered this question via email as well but I wanted to answer here for the benefit of others with the same question. Yes, GP Conditional Logic Dates is supported with confirmations for exactly this use-case. :)
Thank you very much for this! I hope you can answer my question (obviously not an expert).. I’m trying to add a timestamp conditional to a field so it would show or hide depending if a specific date is selected on a date picker. Is this possible?
Hi Alejandra, yep, that’s what this snippet does (in the article above). If you want to make it even easier on yourself, you can purchase Gravity Perks and use the GP Conditional Logic Dates perk.
Hi David,
Apologies if this has been asked before. Looking to create multiple notification options where it can be sent to one email address during normal work hours and a different address outside of those times. M-F 7AM-5PM it goes to aaa@aaa.com and nights & weekends it goes to bbb@bbb.com. GP Conditional Logic Dates seems to only offer the day of the week, but not the time of day.
Any ideas?
Hi Scott, GP Conditional Logic Dates does not yet support Time fields or working with the current time. If you’d like to commission this feature on an accelerated timeline, get in touch.
Is it possible to this kind of conditional logic? If a person selects a date and it falls on sunday, I want option 1 to show up, on monday, option2, tuesday option3 etc
Yes, sir. You’ll want to pick up a copy of GP Conditional Logic Dates. You can then create conditional logic like this (http://grab.by/PFa8).
Hi, I am very interested in this plugin. Is it possible to make a conditional logic when selecting week days or weekends? I have a service website that offer weekend services and would like to show all fields when someone selects a week day or different fields when they select a weekend.
Thanks a lot, Fred Dox
Yes, sir. Here’s how you’d set that up:
That’s it. :)
I can’t see your screenshots… just installed the plugin thought I might figure it out myself. Please would you explain me again how can I do a conditional logic for a drop down if someone selects a week day and another one if they select a weekend day. Thanks
I just figured it out. Turns out I can type each day (monday, tuesday etc…) thanks for this great plugin. Saved me hours of working around GF css. Thanks a lot.
Awesome, Fred. Glad you were able to get this sorted. Let me know if you have any other questions. :)
Hi, How can i do to use timestamp to show fields only for users registered before a “timestamp” date ? Thanks for your help
Hi Fabien, I’ve answered this via email. :)
Is there a way to do with the Conditional Logic that 10% is calculated after the 15th of every month when the form is submitted?
Hi Des, do you meant it adds a 10% fee if the form is submitted after the 15th of the current month? If so, yes but you will need GP Conditional Logic Dates. With it, you can setup a Product field to only appear with a conditional logic rule like this:
Show this field if all of the following match:
[ Date Field ] [ is greater ] [ {month}/15/{year} ]
Hey how can i disble past year showing in dateicker using date filed in gravity form
Hi viral, with GP Limit Dates you can restrict the available date range. Here’s a tutorial that is close to what you’re looking for.
https://gravitywiz.com/how-to-require-a-future-or-past-date-with-gravity-forms-date-picker/
Would love to use this snippet on my site. Cannot for the life of me figure out where to paste the snippet. I have looked everywhere. Could you please expand upon step 1? All the rest makes sense to me.
Thanks!
Hi Nicole, your theme has a file called “functions.php”. You’ll want to open this file via FTP and paste this snippet at the bottom. Make sure to remove the opening <?php from the snippet. This might also be helpful: https://gravitywiz.com/documentation/snippet-troubleshooting/
Also wanted to mention that if you’d prefer to do this without code, GP Conditional Logic Dates is a plugin that provides this functionality and a whole lot more!
I am trying to figure out how to calculate the price per week depending on the date. So for example the price per week for the accommodation from January 1 to May 15 is 300 dollars per week. However, between May 16 to Nov 15 is 350 dollars per week. So if someone is registering on May 1 and wants to stay for a total of 6 weeks, he would pay 300 dollars for the first two weeks and then 350 for the last 4 weeks. How can i make the form calculate this?
First, I would use GP Conditional Logic Dates to accomplish this. It’ll be a lot easier. Next, you can either create multiple products and then show and hide the correct product (by price) based on the Date selected (via the GP Conditional Logic Dates perk) – or – you can keep one Product field and change the price with the GP Conditional Pricing plugin. The demo for that perk actually shows some date-based pricing logic.
Hey Dave,
Again my compliments for a snippet of yours; they work really well!
I was wondering if you have an idea about the following challenge: I do want to use this snippet, but in stead of a fixed date (so with a UNIX timestamp), I would like to always take the day of today as ‘starting point’ for the counting.
A bit more explanation: I am a travel agent and would like the flight tickets I sell, to automatically change in prize (in other words: other product fields to be shown) depending on the number of days from today someone wants to book a ticket for. So: higher price if the selected date is today (so today + 0) and a lower price if they want to book a ticket for in a week (so today + 7 days).
Hope you can help me out with this :) .
Thanks in advance!
Best regards,
Johan
Hi Johan, GP Conditional Logic Dates supports a special merge tag
{today}
. This merge tag supports a special modifier for extending (or reducing) the date:{today:+7 days}
. You could then combine this with GP Conditional Pricing to change the price of your product depending on the selected date. Here’s an example of what the logic might look like (example).Dave,
So with the updates to the twenty-twelve theme the Timestamp doesn’t want to work for me.
Pasting <?php /** * Use Gravity Forms Conditional Logic with Dates * https://gravitywiz.com/use-gravity-forms-conditional-logic-with-dates/ */ add_filter(“gform_field_value_timestamp”, “gwiz_populate_timestamp”); function gwiz_populate_timestamp( $value ){ return time(); }
into the functions.php breaks the file.
with the following error:
Parse error: syntax error, unexpected ‘<‘ in /xxxx/xxxx/xxxxxx/xxxxxx/pages/wp-content/themes/twentytwelve/functions.php on line 12
This script was a huge help but now it seems to leave me hanging…. please help.
Hi Charles, not sure why it would randomly break but here are some tips for reinstallation that might help: https://gravitywiz.com/documentation/snippet-troubleshooting/
Hi David, Thanks for creating this great bit of code. Can it also be adapted to work with times? E.g. if I have a time field and I wanted to apply conditional logic in a later field which used the times inputted earlier. Hope this makes sense. Thanks, Catharine
Hi Catherine, this is a great idea and is something that I’d like to implement in the future. For now, there isn’t a simple way to add support for it in the same way as the dates here.
Dave, I want to start by saying this code is such a blessing. We’ve struggles with so many work aroundss that it was very difficult and had lots of visitors complaining. Thanks.
With that said, and meant, I am having an issue when it comes to drop down product in Gravity Forms…
When I have a single product the code works great (again, very thankful) but when I add a product with three options via drop down menu it breaks and doesn’t show that field. Any suggestions?
I created an example: http://www.bciohio.com/pages/?p=1738
When you select registering as an individual the which show the issue the drop down to choose the event(s) they are attending will not show up (it has the condition set). When registering as Husband & Wife you’ll see the drop down does display as there is no condition.
Hope that helps
Never mind… it work on the conditional page… now I have to think this through.
Thanks again for a great code.
Ok, my pleasure! Make sure you check out Gravity Perks as well for the awesome GP Conditional Logic Dates which expands on this basic idea. :)
Great tutorial. Thanks!
My pleasure!
Hi!
I’m helping a cab company and they don’t want people to place bookings closer than 24 hours.
Would it be possible to deactivate the send button if the time set in the time field is within the next 24 hours from booking?
Regards Pelle
Hi Pelle, I don’t currently have a solution for this. If you’d like to commission me to write a snippet to accomplish this, get in touch.
Hi, how can i create variation for price using text input field? I try many plugins already, and waste few days for work and money…my project drives me crazy ;/ I try to achieve something like that: If width = 20cm to 40cm and height = 60cm to 80cm then price =myValue I need use input fields, i build this with variation in WooComm. but its to heavy for site… is there a way to achieve that with conditional logics? I dont want to buy another useless plugin ;/
I have the Gravity Perks package (and love it!) but I am curious if this Date snippet could be used with Notifications?
For example, I send out a first payment reminder to my new clients two weeks before their first payment is due. (I do not send any additional reminders, just on this first one.) On my Gravity Form, I have name, email address, upload file, and first payment date fields. Could this Date snippet be used to send a Notification if that First Payment Date field is equal to or less than two weeks from today’s date?
Hello David. Do you have a Perk (in the works) that will allow to remove a product option or checkbox based on a date? We basically have a list of events open for registration, and to allow for multiple event signup, they are listed as options under a hidden product. The issue is, i now need to go in every week and delete the event (option) that has just passed – is there a way to hide the option based on the date?
Thanks! Mike
Hi Michael, the closest perk I have is the GP Conditional Logic Dates. Unfortunately, this would not provide the option to show/hide a specific option of an Option field but rather the entire field. You could create multiple copies of the option field, each with one of the options removed depending on the date. Not ideal but one way to accomplish it.