nickelus Posted August 25, 2009 Share Posted August 25, 2009 i've been trying to set an option value that posts to a variable which is switched based on say Last week(past 7 days), last month(past 30days),etc.. then generates two vaiables a start and end date to be used for mysql query Hers my latest attempt <?php if(isset($_POST['submit'])){ $freq = $_POST['freq']; switch ($freq) { case "This Week":{ $freq=date('Y-m-d', strtotime("-7 days"));break; } case "Last Week":{ $freq=date('Y-m-d', strtotime("-14 days"));break; } case "YTD":{ $freq=date('Y-m-d', strtotime("-365 days"));break; } case "This Month":{ $freq=date('Y-m-d', strtotime("-30 days"));break; } case "Last Month":{ $freq=date('Y-m-d', strtotime("-60 days"));break; } case "This Quarter":{ $freq=date('Y-m-d', strtotime("-120 days"));break; } case "Last Quarter":{ $freq=date('Y-m-d', strtotime("-240 days"));break; } } $sDate = $freq; echo $sDate; $freq = $_POST['freq']; $d = mktime(0,0,0,$month,$day,$year); switch ($freq) { case "This Week":{ $freq=date($sDate,strtotime("+7 days",$d));break; } case "Last Week":{ $freq=date(date("m-d-Y",$sDate),strtotime("+7 days",$d));break; } case "YTD":{ $freq=date($sDate,strtotime("+365 days",$d));break; } case "This Month":{ $freq=date($sDate,strtotime("+30 days",$d));break; } case "Last Month":{ $freq=date($sDate,strtotime("+30 days",$d));break; } case "This Quarter":{ $freq=date($sDate,strtotime("+120 days",$d));break; } case "Last Quarter":{ $freq=date($sDate,strtotime("+120 days",$d));break; } } $eDate = $freq;echo $eDate; } ?> <form action="test_dates.php" method="post"> <table> <tr> <td>Report Scope: </td> <td> <select name="freq" value=""> <option <?php if(isset($freq)&&($freq=="")){ echo "selected";}?>>(Choose One)</option> <option value="This Week" <?php if(isset($freq)&&($freq=="This Week")){ echo "selected";}?>>This Week</option> <option value="Last Week"<?php if(isset($freq)&&($freq=="Last Week")){ echo "selected";}?>>Last Week</option> <option value="YTD"<?php if(isset($freq)&&($freq=="YTD")){ echo "selected";}?>>YTD</option> <option value="This Month"<?php if(isset($freq)&&($freq=="This Month")){ echo "selected";}?>>This Month</option> <option value="Last Month"<?php if(isset($freq)&&($freq=="Last Month")){ echo "selected";}?>>Last Month</option> <option value="This Quarter"<?php if(isset($freq)&&($freq=="This Quarter")){ echo "selected";}?>>This Quarter</option> <option value="Last Quarter"<?php if(isset($freq)&&($freq=="Last Quarter")){ echo "selected";}?>>Last Quarter</option> </select> </td> </tr> <tr><td> </td><td><input type="submit" name="submit" value="Submit"></td></tr> </table> </form> Link to comment https://forums.phpfreaks.com/topic/171811-dates-for-reporting-span/ Share on other sites More sharing options...
nickelus Posted August 25, 2009 Author Share Posted August 25, 2009 well i've tried strtotime and mktime, and date() functions in various combinations but still frankenstein the latest is still not giving back a valid end date strtotime(date("Y-m-d", strtotime($date)) . " +1 day"); Link to comment https://forums.phpfreaks.com/topic/171811-dates-for-reporting-span/#findComment-906019 Share on other sites More sharing options...
nickelus Posted August 25, 2009 Author Share Posted August 25, 2009 getting closer date("Y-m-d",strtotime("+7 days", date("Y-m-d",$sDate))) but now my end date is being calc'ed from todays date and i was trying to make it from start date Link to comment https://forums.phpfreaks.com/topic/171811-dates-for-reporting-span/#findComment-906044 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.