Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2012-03-24
7
Medium Priority
?
264 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
5 Comments
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
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 111

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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: 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.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

877 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