Solved

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

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

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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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 …
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 the basics of jQuery including how to code hide show and toggles. 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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now