Solved

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

Posted on 2012-03-24
7
234 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

785 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