How to set default date in ToolJet.com app

Target: Create a variable which has the default date as value. Then use this value as default for date picker component in ToolJet app.

Steps:

  1. Add new query of type “Run JavaScript code”
  2. In the code section paste the following code:
    const currentDate = new Date();

    const year = currentDate.getFullYear();
    const month = String(currentDate.getMonth() + 1).padStart(2,'0'); // Months are 0-indexed
    const day = String(currentDate.getDate()).padStart(2, '0');  

    today = `${year}-${month}-${day}`;

    actions.setVariable('dt', today);
    return actions.getVariable('dt');
  3. Below the code make sure to switch ON in Settings “Run this query on application load?”
  4. Now you can use the created value in the variable “dt” in any Date picker component by simply putting the following text in “Default value” property: “{{variables.dt}}