Link to home
Start Free TrialLog in
Avatar of fondulac
fondulacFlag for United States of America

asked on

Code needed to calculate date 1 week, 16 days, 3 weeks and 6 weeks from today

Hi,

I am needing code for our intranet website that will calculate future dates (1 week, 16 days, 3 weeks and 6 weeks) from the current day's date. It doesn't have to be PHP, but since we use Wordpress, I thought that might work best. I am not a programmer, and do not know a thing about programming languages. Therefore, any and all help/suggestions are greatly appreciated! Thanks in advance.
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

if you add days in your current date, you will get future dates easily

function getDateAfterDays ( noOfDays )
{
   var noOfMilliseconds = noOfDays * 24 * 60 * 60 * 1000;
   var currentDateMilliseconds = new Date ().getTime();
   var futureDate = new Date ( currentDateMilliseconds + noOfMilliseconds  );
   return futureDate;  
}
This article will show you how to get elapsed time periods very easily.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

I'll show you a tested-and-working example in a moment.  Best, ~Ray
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<script language="JavaScript"><!--
function addDays(myDate,days) {
return new Date(myDate.getTime() + days*24*60*60*1000);
}

alert(addDays(new Date(),-100));
//--></script>
Avatar of fondulac

ASKER

I apologize for the delay in responding.  I had an incredibly busy day at work. I will test your solutions as soon as I get an opportunity. I'll be sure to get back with you. Thank you!