我尝试创建一个查询,该查询从名为$ incorporation_date的文本字段中获取用户输入。
查询理念
$sql = "SELECT * FROM companies WHERE incorporation_date LIKE '%%%%/%%/%%" . $incorporation_date . "%%%%/%%/%%'";
我如何制作它以便您可以使用SQL来显示您输入的提交格式的值。
搜索范例2015-06-15
答案 0 :(得分:1)
使用Date
或Datetime
并免除其本来会遇到的悲伤
drop table theGuy;
create table theGuy
(
id int not null auto_increment primary key,
fullName varchar(60) not null,
birthDate date not null
);
insert theGuy (fullName,birthDate) values ('Kim Smithers','2002-3-1'),('John Doe','2014-4-5');
select * from theGuy where birthDate>='2000-1-1' and birthDate<='2007-12-31';
select * from theGuy where birthDate between '2000-1-1' and '2007-12-31';
select *,birthDate+interval 45 DAY as BirthCertAvail from theGuy;
select *,datediff(curdate(),birthDate) as DaysAlive from theGuy;
您可能会发现内置例程足够,例如间隔,而不必重写它们。 ;)