Solved

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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

15 Experts available now in Live!

Get 1:1 Help Now