Difference ( in yrs, months, days) of 2 "Date Picker" dates! (Age Calculator) SOLVED!

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 :slight_smile:

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!

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.

I partially agree with your comment. I have learned tons myself, through youtube, through the links provided, etc.
For those who volunteer their services, the comment is not meant for them.
However, there are many wix employees who are PAID to help answer our questions. Their platform is built for everyday people AND experts to build beautifully designed websites and it is heavily,HEAVILY marketed to individuals with NO EXPERIENCE necessary, as there are WIX EXPERTS who can help them along the way. Is this a SCAM? Should I cancel the money I invest into this company since it is no longer fit for the little people like me? :slight_smile:
If I was a code and javascript expert, guess what…I wouldn’t NEED WIX!
They make a profit off of little people like me :slight_smile:
I did not tell them to log into my editor and write my entire code. I’ve come very far by myself.
However,if you take the time to look a numerous forum questions you will notice some EXPERTS start out by providing an example code SNIPPET to help users along the way. It is not uncommon to see.
However, there are also times that other users complain about the same issue with LAZY experts sending links, as I have stated. and OTHER USERS would also comment
“hey, i’ve check that out. Still not sure how to write this one particular code ( Not entire website) and the LAZY “experts” THEN respond with a snippet code that ends in " Thanks so much” from the user.
Now,Thanks for being a wix internet cop. Go drink some coffee :wink:
you deserve it :slight_smile:
PS: I will post the working code on this post shortly as a VOLUNTEER as soon as I get it together. So all the little people can stop bothering wix employees and they can get paid for link sharing :slight_smile:

For your enthusiasm… “Forum Ninja” <----- “Makes soooooooo much sense. They pay you huh?”

@shaneicewilliams Lol, ok?

Well I won’t object to paying it forward. Though I wish you were right that many Wix employees are paid to help people on this forum, sadly it isn’t the case. And fyi, if I had some snippet to give you I would, but I’ve never attempted what you’re asking for myself and figuring out code for leap years doesn’t sound appealing to me atm. That being said, Wix markets their coding expert services separately, and I wasn’t being pedantic…just trying to offer the other side’s perspective.

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 :wink:

or should i report him as wix fraud since your sooooooo sure they are not hired to answer our questions…

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 :slight_smile:
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!

I think your narcissism speaks for itself. Thanks for the laugh.

@skmedia The only narcissist is the one of us who spends their time feeding their own egos by inserting themselves into random forum posts.
Not to answer questions.
But to feel better about themselves about knowing nothing at all.
So… any terms used in the realm of Narcissism would point to you. My friend.
Have a great day. Hope you learned along the way.
I’ll spare dropping the mic today :slight_smile:
But convo OVER

PS: the links provided should answer all of your questions. Have a great day and keep on wixing!

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)));
}

}