Jump to content

Problem with dates


chrispos

Recommended Posts

Hello all out there in PHP land HELP NEEDED

I have set up a booking system for small hotels. I am using PHP 5 on a Linux cluster.

 

The code works by people selecting the day month and year of the date they start the holiday and then the day they depart. The departure day then has a day chopped off so that when a person looks for room availability the start day of their holiday can start on the last day of any bookings in that period. All the code works fine except for one small detail and I can't see it. i will explain each bit of code so it makes sense.

$d = $_POST['d'];
$m = $_POST['m'];
$y = $_POST['y'];
$d1 = $_POST['d1'];
$m1 = $_POST['m1'];
$y1 = $_POST['y1'];

 

$d is the start day $m is the start month and $y is the start year of the holiday booking.

 

$d1 $m1 and $y1 is the departure date

$date = date ("M-d-Y", mktime(0, 0, 0, $m, $d, $y));
$date1 = date ("t", mktime(0, 0, 0, $m, $d, $y));
$date2 = date ("z", mktime(0, 0, 0, $m, $d, $y));
$date3 = date ("M-d-Y", mktime(0, 0, 0, $m1, $d1, $y1));
$date4 = date ("t", mktime(0, 0, 0, $m1, $d1, $y1));
$date5 = date ("z", mktime(0, 0, 0, $m1, $d1, $y1));

 

I use $date2 as the day of the year for the start of the holiday and $date5 as the last day of the holiday not the departure day. All calculations have been set up to query dates between $date2 and $date5 for available rooms.

if
($date5 == '0' && $m1 == '1' && $y1 == '2013')
{
$d1 = '31'; $m1 = $m ; $y1 = $y; $date5 = '365';
}
elseif
($date5 == '0' && $m1 == '1')
{
$d1 = '31'; $m1 = $m ; $y1 = $y; $date5 = '364';
}
elseif
($d1 == '1' && $m1 > $m && $y == $y1)
{
$d1 = $date1; $m1 = $m; $date5 = $date5 - '1';
}
else
{
$d1 = $d1 - '1'; $m1 = $m1 ; $y1 = $y1; $date5 = $date5 - '1';
}

 

I need to chop a day off from the departure date to make it work but retain the $d, $m, $y, $d1, $m1, $y1. Every thing works fine except for one small problem. When I try to make a booking from December through to January it gives me the same year as December IE 2009 instead of 2010. It returns January fine it is just the year that is the problem.

 

The first line of code is for a leap year IE 2012 you will see 2013 but because the final day of that year is 365 instead of 364. I think you get where I am going with that one.

 

The next lines of code just chop off the days as they should and work fine.

 

I hope this explains my problem.

 

 

Link to comment
Share on other sites

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.