Date Calculations
Learn how to calculate the number of days between two dates and how to add or subtract days from a date using Corvid (a.k.a. Wix Code).
This example shows you how to perform date based calculations such as working out the number of days between two dates or find the date which is 'x' days in the future or past. Try the example below.
#iptDate
Try it!
Select a date to start!
#txtDateDiff
#txtDateAdd
Select a date to start!
Add an onChange event listener for #iptDate to listen for user entry and perform date based calculations accordingly.
The dateDiff variable is calculated as the number of milliseconds between #iptDate less the current date. This number needs to be divided by 1000 to get to the number of seconds, then divided by 60 to get the number of minutes, then divided by 60 to get the number of hours, then divided by 24 to get the number of days. An if-else statement handles the text output depending on if the date chosen is in the future or the past.
The addDate variable is calculated using the setDate function.
Page Code