Hello,
I need some assistance.
I have two date pickers.
DatePicker1 allows the user to select the day he/she 1st opened their credit card account.
DatePicker2 is disabled and set to “today’s date” by default.
I would like to calculate how long they have had the account opened in Years,Months, Days.
for example:
If the user selected the Account Open datepicker1 as: January 1 2015
and the hidden “Today’s” datepicker2 is: April 10 2019
I would like to subtract the account date by today’s date for a result of:
4 years 3 months 9 days
I am willing to settle for just the Years & Months difference if the days is too complicated.
Here is my desperate attempt at figuring out a code: ( That does not work, of course )
$w.onReady( function () {
getDates();
});
export function datePicker1_change(event, $w) {
let date1 = $w(“#datePicker1”).value;
getDates();
let date2 = $w(“#datePicker2”).value;
getDates();
}
export function datePicker2_viewportEnter(event) {
let date2 = $w(“#datePicker2”).value;
getDates();
}
export function date_diff() {
let dt1 = new Date($w(“#datePicker1”).value);
let dt2 = new Date($w(“#datePicker2”).value);
return Math.floor((Date.UTC(dt2.getFullYear()) - Date.UTC(dt1.getFullYear()) ));
}
function getDates(){
let diff = date_diff();
const dates = (Number(diff));
$w(“#test1”).text = String(dates);
}
Just like the example below, but just Years, Months, Days:
Please HELP!
PS: not to sound ungrateful, but… If you plan on putting a link to reference pages or javascript training school, i’m going to self-destruct and implode
I have been greatly helped by wix experts who actually care enough to take the time to provide a example code specific to my needs. But some of you take the lazy way out. ( most users scour the exact links you resend us for months before actually reaching out to a forum ) so imagine the pure disappointment when a “expert” pretty much says
" I dunno, figure it out. here https://www.wix.com/corvid/reference/$w.DatePicker.html "
But i do appreciate some actual guidance and useful information to get me in the right direction!