dadamssg Posted March 7, 2009 Share Posted March 7, 2009 haha, i can NOT get a date calculator working and don't know why. the user dials in a date pushes a button and im trying to program a calculation that determines how many days are between the date selected and today. i thought it was working, it gets the days right anyday from here until 0ct 31 2009 but anything past it calculates a day to many...so Nov 1 it calculates 240 days when it should be 239, but anything before works, everything after is off. suggestions would be awesome <?php session_start(); include("sdateselectfun.php"); $select = mktime(0, 0, 0, $_POST['smonth'], $_POST['sday']+1, $_POST['syear']); $selected = mktime(0, 0, 0, $_POST['smonth'], $_POST['sday'], $_POST['syear']); $today = strtotime("today"); $_SESSION['selected'] = date('F j, Y', $selected); if($select > $today) {$difference = $select - $today;} else { header("Location: http://mysite.com/test/project12.php"); } $days = floor($difference/86400); // OR floor($difference/60/60/24); Quote Link to comment https://forums.phpfreaks.com/topic/148408-solved-desperate-for-a-date/ Share on other sites More sharing options...
Mark Baker Posted March 7, 2009 Share Posted March 7, 2009 And what date does daylight savings end on this year? I'll give a pound to a penny that the problem is all to do with daylight savings. Try $today = mktime(0,0,0,date('n'),date('j'),date('Y')); Quote Link to comment https://forums.phpfreaks.com/topic/148408-solved-desperate-for-a-date/#findComment-779183 Share on other sites More sharing options...
Mark Baker Posted March 7, 2009 Share Posted March 7, 2009 If that doesn't work, try using the gmmktime() funtion instead of mktime() for all your dates Quote Link to comment https://forums.phpfreaks.com/topic/148408-solved-desperate-for-a-date/#findComment-779192 Share on other sites More sharing options...
dadamssg Posted March 8, 2009 Author Share Posted March 8, 2009 i THINK i fixed it....thanks for the gmmktime suggestion i used that. heres what i did $select is used in my calculation, while $selected is displayed on the page and it aligns and works. $select = gmmktime(0, 0, 0, $_POST['smonth'], $_POST['sday'], $_POST['syear']); $selected = gmmktime(0, 0, 0, $_POST['smonth'], $_POST['sday']+1, $_POST['syear']); $today = gmmktime(0,0,0,date('n'),date('j'),date('Y')); $_SESSION['selected'] = date('F j, Y', $selected); if($select > $today) {$difference = $select - $today;} Quote Link to comment https://forums.phpfreaks.com/topic/148408-solved-desperate-for-a-date/#findComment-779208 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.