• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 802
  • Last Modified:

Add year to date

Is there an easy way to add a year to a date.  Say I have:

var todayDate = "5/5/2006";

I want to make:

nextYearDate = "5/5/2007";

How would I accomplish this?
0
russomr
Asked:
russomr
1 Solution
 
radarshCommented:
<script type="text/javascript">
    var todayDate = '5/5/2006';
    var year = todayDate.match(/\d{4}/g);
    year = parseInt(year) + 1;
    var nextYearDate = todayDate.replace(/\d{4}/g, year);
    alert(nextYearDate);
</script>

________
radarsh
0
 
russomrAuthor Commented:
Works.  Thanks.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now