Jump to content

[SOLVED] desperate for a date


dadamssg

Recommended Posts

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);

 

 

Link to comment
https://forums.phpfreaks.com/topic/148408-solved-desperate-for-a-date/
Share on other sites

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;}

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.