Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.