How to extract the year of the current date

  • Manasota
    Asked on April 26, 2024 at 8:54 AM

    How do I calculate the year of today's date and show it on a form?

  • Manilene JotForm Support
    Replied on April 26, 2024 at 9:04 AM

    Hi Manasota,

    Thanks for reaching out to Jotform Support. Apologies, but I'm not entirely clear on your objective. Could you provide more detail about the matter at hand? This will help me grasp the situation more effectively.

    Once we have a better idea of what’s going on, we’ll be able to come up with a solution.

  • Manasota
    Replied on April 26, 2024 at 9:20 AM

    I collect the current date using the date picker widget. I want to include a field on the form that extracts the year from the current date either into the current date field or into another field for display on the form.

  • Chris_L JotForm Support
    Replied on April 26, 2024 at 9:38 AM

    Hi Manasota,

    Thanks for getting back to us. You can do this using the Substring widget. I'll walk you through setting that up:

    • In Form Builder, click on the Add Form Element menu on the left side of the page.
    • Under the Widgets tab, search for Substring. Drag and drop the widget to your form.
      How to extract the year of the current date Image 1 Screenshot 60
    • Now, select the Date Picker and click on the Gear icon.
    • Under the Advanced tab, click on Field Details.
      How to extract the year of the current date Image 2 Screenshot 71
    • In the text box under Field Ids, copy #year_3.
      How to extract the year of the current date Image 3 Screenshot 82
    • Select the Substring and click on the Wand icon. Configure the widget just like what you see in the screenshot below:
      How to extract the year of the current date Image 4 Screenshot 93
    • Finally, click on Update Widget. That's it.

    Here's a screencast of the expected result:

    How to extract the year of the current date Image 5 Screenshot 104

    Reach out again if you need any other help.

  • Manasota
    Replied on April 26, 2024 at 10:14 AM

    Perfect. Thanks a lot

 
Your Answer