user1137370
user1137370

Reputation: 137

MKTime - error if month is different

I need to check whether the departure-date is after the arrivaldate.

For example:

arrivaldate 13/3/2012 departure 14/3/2012 -> error = false
arrivaldate 13/3/2012 departure 12/3/2012 -> error = true

$timestamp = mktime(0,0,0,$arrivaldd,$arrivalmm,$arrivalyy);

$timestamp2 = mktime(0,0,0,$departuredd,$departuremm,$departureyy);

if ($timestamp2 <= $timestamp) {$error1 = true;} else {$error1 = false;}

It works fine, but $error is set false if arrivaldate is 31/3/2012 and departure date 1/4/2012.

Upvotes: 0

Views: 161

Answers (3)

Poonam
Poonam

Reputation: 4631

in this function mktime parameters are as follows

mktime(hrs,min,sec,month,day,year)

and you are giving day first and then month.so timestamp generated is departure higher than arrival so you are getting error

Upvotes: 2

Marc B
Marc B

Reputation: 360682

That's because mktime's arguments are:

mktime(hours, minute, seconds, month, day, year);

You've got the month/day arguments reversed

Upvotes: 2

user254875486
user254875486

Reputation: 11240

mktime expects is parameters in the following order: hour, minute, second, month, day, year. You have the day and month in reversed order. See the PHP.net reference page

Upvotes: 3

Related Questions