Solved

how to calculate 2 weeks from now

Posted on 2008-06-26
5
406 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
Comment Utility
php is one of the few languages that makes this real easy.

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

0
 
LVL 31

Expert Comment

by:Frosty555
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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…
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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 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

7 Experts available now in Live!

Get 1:1 Help Now