梳理数字但不在PHP中添加它们

I'm trying to do a server-side validation of the date chosen by user and the current date and here's what I have:

$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$dateval = $year + $month + $day;

if ($dateval - $today < 0) {
$datepassed = 'no';
}
else {
$datepassed = 'yes';    
}

Now as far as I know, everything is working flawlessly except the fact that the $dateval variable just adds up all the numbers instead of putting them together to form the date chosen by the user. for example 20110719 returns 2037. How can I make a veriable that combines the numbers without adding them? Any help is appreciated.

If you're concatenating strings, you should be using the concatenation operator, .:

$dateval = $year . $month . $day;

Otherwise, PHP will be clever and convert your strings to integers, a consequence of weak typing as implemented by the PHP language.

PHP concatination uses . not +. The plus sign is how JavaScript (and probably other languages) concatenate strings.

$dateval = $year . $month . $day;

They must be strings and a . used.

if you want to concatenate them as strings, use the dot (.)

$dateval = $year . $month . $day;

however, since you are working with dates, consider using the mktime function

$dateval = mktime(0, 0, 0, $month, $day, $year)

Simply replace the + (add) with . (concatenate).

$dateval = $year.$month.$day;

You need to add them as a string. A dot operator does that.

Also make sure that format of $dateval is similar to the format of $today (i.e. include dashes if needed):

$dateval = $year.'-'.$month.'-'.$day;