Forum Discussion
RachelHorton-2c
2 years agoCommunity Member
JavaScript help needed - Add 6 months to a date
I'm looking for help with JavaScript. I have code to display the current date in MM/DD/YYYY format. I need to also display a date 6 months into the future. I am not skilled with JavaScript. Any help...
SandeepGadam
2 years agoCommunity Member
Hello Rachel, here is the updated code to get the date for the next 6 months:
var currentDate = new Date();
currentDate.setMonth(currentDate.getMonth() + 6);
var day = currentDate.getDate();
var month = currentDate.getMonth() + 1;
var year = currentDate.getFullYear();
var player = GetPlayer();
var newName = month + "/" + day + "/" + year;
player.SetVar("DateValue", newName);
You can use the setMonth
method of the Date
object to add 6 months to the current date and then we extract the day, month, and year of the new date and update the Date Value. Modifying the "+6" in the second line will get your desired future date.
- RachelHorton-2c2 years agoCommunity Member
Thank you so much!!! This community is awesome.