Jump to content

calculating dates


dadamssg

Recommended Posts

i am trying to calculate the number of days between a date selected and now. it will decided where to send the user based on the number. I thought it was working until right now. if you put in march 9 2009 it will calculate 2 days, which is FALSE. if i put in anything later than two days out, it will calculate a day short. heres the script

 

<?php
session_start();


include("sdateselectfun.php");


$start = strtotime($_POST['smonth']."/".$_POST['sday']."/".$_POST['syear']);
    $today = strtotime("today");

if($start > $today) 
{$difference = $start - $today;}

else { 
   header("Location: http://mysite.com/test/projectbas.php");
     }

    
    $days = floor($difference/86400); // OR floor($difference/60/60/24);

if ($days < 1 )
   {
  
   header("Location: http://www.mysite.com/test/projectbas.php");
   exit;
   }
      else
    {
	 $_SESSION['days'] = $days;
	header("Location: http://www.mysite.com/test/pick.php?days={$_SESSION['days']}");
	exit;
	}

?>

Link to comment
https://forums.phpfreaks.com/topic/148236-calculating-dates/
Share on other sites

Hi

 

I knocked up a tiny test and it appears to just use the date (presume it defaults the time to 00:00).

 

Tried the difference and for me it appears to work.

 

Only thing I can think of is possibly something to do with time zones and what your PC / server thinks the date is

 

All the best

 

Keith

Link to comment
https://forums.phpfreaks.com/topic/148236-calculating-dates/#findComment-778240
Share on other sites

k, i have a SUPER wierd update. if i calculate days between today and march 6, 2010 it works..gives me 365. but ive been trying other dates such as nov 1, 2009 and today and it gives me 239 when it should be 241....what in the world is going on? i created the small form which displays the date selector and submit button as a function...im using it to display the small form in two places on my website, the form uses $_POST. is it possible that the $_POST variable values are getting mixed up????

Link to comment
https://forums.phpfreaks.com/topic/148236-calculating-dates/#findComment-778379
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.