AJM2 Posted February 7, 2022 Share Posted February 7, 2022 I am not sure I am doing this correctly. My goal is to have a button on each side of the page with today's date in the middle as dropdown lists allowing to page through dates (see image) or pick a specific date. I have the code somewhat of working. It will page up tomorrow, next day, next day... and it goes down, yesterday, day before... when starting at today. But once I go either up or down I can't page back in the opposite direction. The ultimate goal is to pass the "current" date into a query to get today's data as you page through. I hope I described this well enough. I don't want to use a date picker where a calendar pops up. Any pointers would be appreciated. <html> <head> <title></title> </head> <body> <form action="calendar_form.php" method="post" name="f1"> <?php error_reporting(E_ALL); ini_set('display_errors', '1'); // Default dates $beginYesterday = date('Y-m-d H:i:s',strtotime('yesterday')); $beginOfDay = date('Y-m-d H:i:s',strtotime('today')); $endOfDay = date('Y-m-d H:i:s',strtotime('tomorrow')); $tomorrow = date('Y-m-d H:i:s', strtotime($beginOfDay . '+1 days')); $f_today = date('m-d-Y', strtotime('today midnight')); $yesterday = date('Y-m-d H:i:s', strtotime('-1 days')); // Check the form was submitted if ($_SERVER['REQUEST_METHOD'] == 'POST') { $yesterday = $_POST['yesterday']; $tomorrow = $_POST['tomorrow']; if($_POST['Submit'] == 'Tomorrow'){ $tomorrow = date('Y-m-d H:i:s', strtotime($tomorrow . '+1 days')); $today = date('m-d-Y', strtotime($_POST['tomorrow'])); $yesterday = date('Y-m-d H:i:s', strtotime($tomorrow . '-1 days')); $f_today = $today; } elseif($_POST['Submit'] == 'Yesterday'){ $tomorrow = date('Y-m-d H:i:s', strtotime($yesterday . '+1 days')); $today = date('m-d-Y', strtotime($_POST['yesterday'])); $yesterday = date('Y-m-d H:i:s', strtotime($yesterday . '-1 days')); $f_today = $today; } } ?> <table border="1" align="center" width="100%"> <input type="hidden" name="yesterday" value=<?php echo $yesterday;?>> <input type="hidden" name="tomorrow" value=<?php echo $tomorrow;?>> <tr> <td align="center" width="20%"><?php echo $yesterday;?><input type="Submit" name="Submit" value="Yesterday"></td> <td align="center" width="60%"> <?php echo $f_today;?></td> <td align="center" width="20%"><input type="Submit" name="Submit" value="Tomorrow"><?php echo $tomorrow;?></td> </tr> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { //<!--- Form view ---> echo"<tr><td>query</td></tr>"; } else{ //<!--- Default view ---> "<tr><td>default</td></tr>"; } ?> </table> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted February 7, 2022 Solution Share Posted February 7, 2022 the operation is to simply either add one day or subtract one day from the current date - <html> <head> <title></title> </head> <body> <form method="post" name="f1"> <?php error_reporting(E_ALL); ini_set('display_errors', '1'); // Default dates $today = date('Y-m-d H:i:s',strtotime('today')); // Check the form was submitted if ($_SERVER['REQUEST_METHOD'] == 'POST') { $today = $_POST['today']; if($_POST['Submit'] == 'Tomorrow'){ $today = date('Y-m-d H:i:s', strtotime($today . '+1 days')); } if($_POST['Submit'] == 'Yesterday'){ $today = date('Y-m-d H:i:s', strtotime($today . '-1 days')); } } ?> <table border="1" align="center" width="100%"> <input type="hidden" name="today" value=<?php echo $today;?>> <tr> <td align="center" width="20%"><input type="Submit" name="Submit" value="Yesterday"></td> <td align="center" width="60%"> <?php echo $today;?></td> <td align="center" width="20%"><input type="Submit" name="Submit" value="Tomorrow"></td> </tr> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { //<!--- Form view ---> echo"<tr><td>query</td></tr>"; } else{ //<!--- Default view ---> "<tr><td>default</td></tr>"; } ?> </table> </form> </body> </html> 1 Quote Link to comment Share on other sites More sharing options...
AJM2 Posted February 8, 2022 Author Share Posted February 8, 2022 I guess I was over complicating this thought process. Thank you for the assistance. Very much appreciated. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.