Finding earliest date greater than today.

  • plott
    Asked on September 21, 2017 at 6:25 AM

    I have an option box that I've loaded with dates.  Is it possible to default to the earliest date that is greater than today?  Or, can I somehow determine that date by using a calculated field?

  • candy
    Replied on September 21, 2017 at 10:04 AM

    The earliest date that greater than today is tomorrow in the normal case. So, adding 1 day to the current day should solve the problem. 

    Firstly, you can set the current date to the date field as you can see the screenshot below:

    Finding earliest date greater than today Screenshot 40

    Secondly, you can set a calculation condition to the date field in order to calculate tomorrow as you can see the screenshot below:

    Finding earliest date greater than today Screenshot 51

    So, it will calculate it as you can see the screenshot below:

    Finding earliest date greater than today Screenshot 62

    If you prefer, you can set the first date field hidden, just to see the one day after.

    I hope this information will be helpful. If you need any further assistance, do not hesitate to contact us.

  • plott
    Replied on September 21, 2017 at 10:14 AM

    Candy - thanks for the response.  However, on my form, I have populated a dropdown with a number of dates (every other Friday).  I want to determine which value from this list is the earliest, yet greater than today - not just grab tomorrow.

    My form is at: https://form.jotform.us/72624051670148

    And I'd be looking to grab the next 'Payroll Date' after today.

    Thanks!

  • aubreybourke
    Replied on September 21, 2017 at 11:49 AM

    Yes its possible. I made a quick demo for you:

    https://form.jotformpro.com/72634600757963

    You can clone it and modify it how you like:

    How to Clone an Existing Form from a URL

    Or if you prefer to build it yourself, here are the steps:

    1. Add a date picker field to your form.

    2. Open the properties for the field (blue gear icon)

    3. On the options tab select current for the default date (this is equal to todays date)

    4. On the options tab enable the calendar popup

    5. On the limits tab uncheck everything except for "Future" and "Fridays"

    6. On the limits tab in the disable date range box add "today>today+6" (this will disable everything from today until six days from now giving you every other Friday).



  • plott
    Replied on September 21, 2017 at 12:25 PM

    OK, I'm almost there.  Is it possible to subtract a fixed date (hidden datepicker set to a default?) from the current day - so that each day this value increases by a day?

  • aubreybourke
    Replied on September 21, 2017 at 12:32 PM

    It should automatically recalculate every day. Because we use the "today" variable. The today variable changes every day.

    So by setting the disable range from "today" to "today+6" you will always get every other Friday.

  • plott
    Replied on September 21, 2017 at 12:36 PM

    Does 'today' also work in the form calculation widget?

  • aubreybourke
    Replied on September 21, 2017 at 12:48 PM

    No I don't believe it does. However you can add a date field, set its value to current (meaning todays date) and then use it in a calculation field.

    Note #1: If you surround the date variable with the datestring function in the calculation field it will return a text representation of the date.

    Note #2: Working with dates can be quite difficult. Here is the official documentation on how to perform calculations on dates/times

    Mastering Date and Time Calculation