How To Calculate “Year Since” Via JQuery

If you’re building a WordPress website and find you need to calculate “year since” via jQuery, the following is an ideal code for that.

An example can be found here: jsfiddle.net/Garconis/fcar9vjn.

Note: You may need to replace $ with jQuery if using within WordPress.

<script>
function yearsSince() {
var d = new Date();
var sinceThen = d.getFullYear()-1979;
$("#sinceDate").html(sinceThen);
}
$(document).ready(function() {
yearsSince();
});
</script>
1979 is <span id="sinceDate">35+</span> years today.
Menu
Google Rating
5.0
Based on 254 reviews
×
Get a Quote