Solved

how to calculate 2 weeks from now

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

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

895 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

16 Experts available now in Live!

Get 1:1 Help Now