Solved

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

Posted on 2012-03-24
7
241 Views
Last Modified: 2013-11-21
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.
0
Comment
Question by:fondulac
7 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 37760930
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;  
}
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 37760989
This article will show you how to get elapsed time periods very easily.
http://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
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37760999
See: http://www.laprbass.com/RAY_temp_fondulac.php

A word of explanation.  The PHP date() function can format dates in lots of different ways.  The YYYY-MM-DD format that you see here as the default output of the function is the ISO8601 standard for representation of dates.  We use the ISO standard because it is easy for people to read and also easy for computers to compare and sort.

HTH and please post back with any questions, ~Ray
<?php // RAY_temp_fondulac.php
error_reporting(E_ALL);
echo "<pre>";


// A FUNCTION TO GET FUTURE DATES
// <snip> (1 week, 16 days, 3 weeks and 6 weeks) from the current day's date. </snip>
function futuredate($elapsed='0 DAYS', $pattern='Y-m-d')
{
    return date($pattern, strtotime('TODAY + ' . $elapsed));
}


// THIS IS PROBABLY ALREADY SET IN WORDPRESS
date_default_timezone_set('America/Chicago');


// TEST THE FUNCTION A FEW DIFFERENT WAYS
echo PHP_EOL . futureDate();
echo PHP_EOL . futureDate('1 week');
echo PHP_EOL . futureDate('16 days');
echo PHP_EOL . futureDate('3 weeks');
echo PHP_EOL . futureDate('6 weeks', 'l, F jS, Y');

Open in new window

0
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37761001
<script language="JavaScript"><!--
function addDays(myDate,days) {
return new Date(myDate.getTime() + days*24*60*60*1000);
}

alert(addDays(new Date(),-100));
//--></script>
0
 
LVL 1

Author Comment

by:fondulac
ID: 37762208
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!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question