Solved

how to calculate 2 weeks from now

Posted on 2008-06-26
5
446 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

632 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