PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table tbl (id int primary key auto_increment, name varchar(64), gender char(1), dob date); insert into tbl (name, gender, dob) values ('Bob', 'M', '1991-05-12'), ('Aloce', 'F', '1994-06-01');
Copy Clear
Copy Format Clear
<?php $query = "SELECT * FROM tbl WHERE dob BETWEEN DATE_SUB(:date, INTERVAL 2 YEAR) AND DATE_ADD(:date, INTERVAL 3 YEAR)"; $stmt = $pdo->prepare($query); $stmt->execute([':date'=>'1993-01-01']); $res = $stmt->fetchAll(PDO::FETCH_ASSOC); var_export($res);
Show:  
Copy Clear