Solved

how to calculate 2 weeks from now

Posted on 2008-06-26
5
436 Views
Last Modified: 2013-12-13
I have dates in this format
6-30-2008
12-31-2008
12-1-2008
12-1-2008
5-30-2008
6-30-2008
7-7-2008
2-26-2009
12-1-2008
2-27-2008
2-11-2009
2-11-2008
2-11-2009
2-11-2008
5-1-2008
5-1-2009
5-30-2008
 and I want to calculate which date from above falls within two weeks from today. How would I go calculate that
Thanks
0
Comment
Question by:syedasimmeesaq
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 31

Expert Comment

by:Frosty555
ID: 21878429
php is one of the few languages that makes this real easy.

$futuredate = strtotime($originaldate . " +2 weeks")

0
 
LVL 31

Expert Comment

by:Frosty555
ID: 21878502
oh and I guess if you want it back in the same string format that you had the original date in, as opposed to a numeric php date type:

$futuredate = date("d-m-Y", strtotime($originaldate . " +2 weeks"));
0
 
LVL 31

Accepted Solution

by:
Frosty555 earned 500 total points
ID: 21878540
Finally, if you want to calculate what the date is two weeks from NOW:

$futuredate = strtotime(date("d-m-Y") . " +2 weeks");

For each date in your list, do
if( strtotime($originaldate) == $futuredate )  {
    echo "that's the one.";
}
0
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 21879117
I did this
<?
$sqlmain = mysql_query("select * from table");
$futuredate = strtotime(date("d-m-Y") . " +2 weeks");
$row = mysql_fetch_array($sqlmain);
$numrows=mysql_num_rows($sqlmain);
?>
<table width="90%" border="2">
 <tr>
 <td>Start Date</td>
    <td>End Date</td>
    <td>Future Date </td>
    <td>Matched</td>
   
    </tr>
<?
$i = 0;
  while($i<$numrows){

$startdate = mysql_result($sqlmain, $i, "bstart_district");
$enddate = mysql_result($sqlmain, $i, "bend_distroct");

 
?>  
  <tr>
    <td><?php echo $startdate; ?></td>
    <td><?php echo $enddate; ?></td>
    <td><?php echo $futuredate; ?></td>
    <td>
   <? if( strtotime($startdate) == $futuredate )  {
    echo "that's the one.";
}
 ?>  

It puts the date in some other format like this

Start Date  End Date          Future Date          Matched
9-25-2007  9-26-2007     1215666000  
9-12-2007  9-12-2007     1215666000  
9-25-2007  9-26-2007     1215666000


thanks
0
 
LVL 31

Expert Comment

by:Frosty555
ID: 21880743
Yes, the format is an internal PHP date format - it represents the number of seconds since jan 1900 or something like that. I don't quite remember.

It is best to deal with this format as much as possible. When extracting data from MySql, the date will come as a string. You use strtotime() to convert the string to a PHP date number type which can be used in PHP's wide range of date functions. Then you use date() to reconvert it back to a string for display purposes.

$formatteddate = date("d-m-Y", $futuredate);
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

710 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