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!
FOUND A SOLUTION!!
You will need 6 total user input fields to calculate within.
1. Current Month
2. Current Year
3. Year if less or equal ( if the user inputs a month less than or equal to current month)
4. Month if less or equal ( same as above)
5. Year Greater than ( if user selects a month greater than current month)
ex: current month is april, if user selects may,june,july etc the code will calculate differently
6. Month Greater Than (Same as above)
Code:
$w.onReady(function () { $w("#Preloader").expand(); const millisecondsToDelay = 6000; setTimeout(() => { $w("#Preloader").collapse();
}, millisecondsToDelay);
// The current month is pulled // const today = new Date(); const options = { month: "numeric", };
$w("#CurrentMonth").value = today.toLocaleDateString("en-US", options);
// the current year is set //
var year = 2019; $w('#CurrentYear').value = "2019"; }); export function SaveA1_click(event) { $w('#SaveA1').collapse(); $w('#A1Continue').expand(); $w('#A1Month').value = (Number($w('#A1Month').value)); $w('#YearDiff').show(); var UseCheck = $w('#TypeA1').value; var MonthCheck = (Number($w('#CurrentMonth').value)); var AccountMonth= (Number($w('#A1Month').value)) var MonthDiff = (Number($w('#A1Month').value) + (Number($w('#CurrentMonth').value))); var MonthFix = 12 - (Number($w('#A1Month').value)) var NewMonth = MonthFix + MonthCheck; $w('#YearResult').value = (Number($w('#CurrentYear').value - (Number($w('#A1Year').value)))); var NewYearResult = (Number($w('#YearResult').value) - 1); var NewMonthResult = NewMonth;
if (UseCheck === "1"){ $w('#UseA1').expand(); } else if (UseCheck === "2"){ $w('#UseA1').collapse(); } else if (UseCheck === "3"){ $w('#UseA1').collapse(); }
if (MonthCheck < AccountMonth){ $w('#MonthResult').value = (Number($w('#CurrentMonth').value - (Number($w('#A1Month').value)))); $w('#YearResult').value = (Number($w('#CurrentYear').value - (Number($w('#A1Year').value)))); $w('#input4').value = NewYearResult; $w('#input5').value = NewMonthResult; $w('#YearDiff').text = "This account has an age of: " + $w('#input4').value + " yrs " + "& " + $w('#input5').value + " months"; $w('#pushA1Age').value = (Number($w('#input4').value) + "." + (Number($w('#input5').value))); } else if (MonthCheck >= AccountMonth){ $w('#YearResult').value = (Number($w('#CurrentYear').value - (Number($w('#A1Year').value)))); $w('#MonthResult').value = (Number($w('#CurrentMonth').value - (Number($w('#A1Month').value)))); $w('#YearDiff').text = "This account has an age of: " + $w('#YearResult').value + " yrs " + "& " + $w('#MonthResult').value + " months"; $w('#pushA1Age').value = (Number($w('#YearResult').value) + "." + (Number($w('#MonthResult').value))); }
}
So as i said previously:
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!
David,
Let me help you out...
They are HIRING You like links right?
https://www.wix.com/jobs/locations/tel-aviv/positions/2819
https://www.wix.com/jobs/locations/tel-aviv/positions/2920
https://www.wix.com/jobs/locations/tel-aviv/positions/3057
https://www.wix.com/jobs/locations/tel-aviv/positions
Then why hire people well informed people to answer questions online? The only one sadly mistaken is:
Y-O-U.
Talk to the community AND EXPERTS WHO BUILT WIX? huh.... wait theres more mr.KnowItAll but knows Nada.....
and the beat goes on....
Trust me, there are paid experts who regularly respond to answer users questions.
and i QUOTE from WIX and not the hidden wix cop-out Major of excuses provided by you.....
"Wix’s Knowledge Base team. We’re a group of experts who use our unique understanding of Wix products to provide support content to over 130 million users around the world. We break down complicated concepts into concise, engaging text. We work with multiple stakeholders in the company to produce help articles and tutorials that address our users’ needs."
they should instead write.....
"We provide links to documentation already readily available to our users and will not provide further assistance in a conscious effort to encourage our users to learn JavaScript and code on their own.
also, to add bleach to your wound of pettiness and know nothing at all mentality. i jave PROOF employees are paid! haha from a previous post of mines. he acknowledges he woks wiythin wix and could access my editor to help me out...
since you like LINKS.
HERE IS PROOF THEY ARE EMPLOYEES WITH BACK ACCESS TO OUR EDITORS! HE CLRARLY STATES IT AND HELPED ME OUT AFTER VIEWING.... WITHOUT COMPLAINING AND CRYING TO FORUMNINJA ABOUT IT!
https://www.wix.com/code/home/forum/community-discussion/user-input-dropdown-connecting-values-to-elements-beginner-help%3Fpage%3D1%26dl%3D5c3cdab43b624100cbf7e6a7
he was ACTUALLY wanting to HELP and was AUTHORIZED WIX PERSONNEL.
Goodbye David ;-)
or should i report him as wix fraud since your sooooooo sure they are not hired to answer our questions.......
Hey Shaneice,
It's not really a matter of taking the lazy way out of helping so much as encouraging you to learn how to do something so you can debug it later yourself. Most of the people helping are not paid by Wix, nor by you so it's unrealistic to expect people will write code for you or debug it. We do so usually to be nice if it doesn't take up too much time. Hope it doesn't come off as rude, but there's a time when all of us have to scour and struggle, newbie or not.