Title: Predefine date
Last modified: October 31, 2023

---

# Predefine date

 *  Resolved [itzikn](https://wordpress.org/support/users/itzikn/)
 * (@itzikn)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/predefine-date/)
 * I have 2 date input field and i want to init the first as first date of current
   month and year, and the 2nd as last date of current and year.
 *  I can set the fields by html but the automatic calculation for other field not
   done.
 * Any help ?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/predefine-date/#post-17163690)
 * Hello [@itzikn](https://wordpress.org/support/users/itzikn/),
 * Thank you very much for using our plugin. I’ll try to describe the process with
   a hypothetical example. Assuming the date fields are fieldname1 and fieldname2,
   respectively, and their date format is mm/dd/yyyy.
 * Insert a calculated field in the form and enter the following piece of code as
   its equation (The calculated field can be hidden by ticking a checkbox in its
   settings):
 *     ```wp-block-code
       (function(){
       let first = TODAY(),
       last = EOMONTH(TODAY());
   
       first.setDate(1);
   
       getField(fieldname1|n).setVal(GETDATETIMESTRING(first, 'mm/dd/yyyy'));
   
       getField(fieldname2|n).setVal(GETDATETIMESTRING(last, 'mm/dd/yyyy'));
   
       })()
       ```
   
 * There are other alternatives. For example, the following equation is equivalent
   to the previous one:
 *     ```wp-block-code
       (function(){
       let first = MONTH()+'/1/'+YEAR(),
       last = MONTH()+'/'+DAY(EOMONTH(TODAY()))+'/'+YEAR();
   
       getField(fieldname1|n).setVal(first);
   
       getField(fieldname2|n).setVal(last);
   
       })()
       ```
   
 * Best regards.
 *  Thread Starter [itzikn](https://wordpress.org/support/users/itzikn/)
 * (@itzikn)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/predefine-date/#post-17163776)
 * Thanks

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Predefine date’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [itzikn](https://wordpress.org/support/users/itzikn/)
 * Last activity: [2 years, 7 months ago](https://wordpress.org/support/topic/predefine-date/#post-17163776)
 * Status: resolved