- This topic has 2 replies, 1 voice, and was last updated 2 months, 1 week ago by greg8872.
- AuthorPosts
- November 7, 2020 at 11:26 am #1730rabinsky_9269Participant
Hello, basically what the title says.
I would like to have a code that I can input in the about me page to show my age in realtime.
For example, I’m John and I am [code here] years old.
Google search did not really help as most codes are not very user friendly and need separate plugins. I just want to run it inside of a block.
​
Thanks!
November 7, 2020 at 11:26 am #1731ResearchMan123Guestfunction _calculateAge(birthday) { // birthday is a date
var ageDifMs = Date.now() – birthday.getTime();
var ageDate = new Date(ageDifMs); // miliseconds from epoch
return Math.abs(ageDate.getUTCFullYear() – 1970);
}const dateOfBirth = new Date(’11/15/1995′);
console.log(_calculateAge(dateOfBirth) + ” years old”);
just put whatever your date of birth is in the date of birth variable, and then instead of console log just use it to change whatever text you wantNovember 7, 2020 at 11:26 am #1732greg8872GuestThis made me think of this…. https://www.youtube.com/watch?v=qHDSNs9wBpU&feature=youtu.be&t=68
While not as picky as the clip, things like the location of the viewer (and if you are calculating server side, where the server is located) can be a little tricky that 24 hour period around midnight of their birthday.
- AuthorPosts
- You must be logged in to reply to this topic.