mySQL日期时间比较语法错误

发布于 2024-11-30 09:28:01 字数 331 浏览 0 评论 0原文

我正在为我的母亲制作一个预订系统,但在锁定已预订的时间时遇到一些问题。

这是代码:

SELECT event_start
FROM annagretasjoberg
WHEREevent_start BETWEEN 2011-8-1 1:30:00 AND 2011-8-1 2:0:00

这是来自 mySQL 服务器的回复:

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行“1:30:00 和 2011-8-1 2:0:00”附近使用的正确语法

I am making a booking system for my mother and I have some problems locking already booked times.

Here is the code:

SELECT event_start
FROM annagretasjoberg
WHEREevent_start BETWEEN 2011-8-1 1:30:00 AND 2011-8-1 2:0:00

Here is the reply from the mySQL server:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1:30:00 and 2011-8-1 2:0:00' at line 1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

倾听心声的旋律 2024-12-07 09:28:01

日期数据类型必须用引号引起来

select event_start from annagretasjoberg where event_start 
between '2011-8-1 1:30:00' and '2011-8-1 2:0:00'

Date datatype must be enclosed in quotes:

select event_start from annagretasjoberg where event_start 
between '2011-8-1 1:30:00' and '2011-8-1 2:0:00'
或十年 2024-12-07 09:28:01

您需要将示例日期放在单引号中,以便 SQL 正确解析它:

SELECT event_start
FROM annagretasjoberg
WHERE event_start BETWEEN event_start between '2011-8-1 1:30:00' and '2011-8-1 2:0:00'

You need to put your example dates in single quotes in order for SQL to parse it correctly:

SELECT event_start
FROM annagretasjoberg
WHERE event_start BETWEEN event_start between '2011-8-1 1:30:00' and '2011-8-1 2:0:00'
凉宸 2024-12-07 09:28:01

在您的日期周围加上引号:

SELECT event_start
FROM annagretasjoberg
WHEREevent_start BETWEEN '2011-8-1 1:30:00' AND '2011-8-1 2:0:00'

Put quotes around your dates:

SELECT event_start
FROM annagretasjoberg
WHEREevent_start BETWEEN '2011-8-1 1:30:00' AND '2011-8-1 2:0:00'
高跟鞋的旋律 2024-12-07 09:28:01

您必须将日期值放在单引号之间,例如

select event_start from annagretasjoberg where event_start between '2011-8-1 1:30:00' and '2011-8-1 2:0:00'

我也鼓励您使用参数化查询。

You have to put the date values between single quotes, e.g.

select event_start from annagretasjoberg where event_start between '2011-8-1 1:30:00' and '2011-8-1 2:0:00'

I also would encourage you to use parametrized queries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文