作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
id birth
-----------------------------
1 1079280000 (2004-03-15)
2 987264000 (2001-04-15)
3 1042560000 (2003-01-15)
birth
时间戳到
1300118400
(2011-03-15) 用于 sql;
<?php
$now = strtotime('2011-03-04');// today's timestamp
$sql = "SELECT * FROM member
WHERE birth(1079280000 convert to 1300118400) > $now";
?>
Results
id birth
---------------
1 1079280000 (2004-03-15)
2 987264000 (2001-04-15)
birth
转换为当年生日的
timestamp
.
最佳答案
无子选择解决方案:
SELECT
id,
UNIX_TIMESTAMP(
FROM_UNIXTIME(birth) +
INTERVAL (YEAR(CURDATE()) - YEAR(FROM_UNIXTIME(birth))) YEAR
) AS birthday
FROM member
WHERE NOW() < FROM_UNIXTIME(birth) +
INTERVAL (YEAR(CURDATE()) - YEAR(FROM_UNIXTIME(birth))) YEAR
/* Stage 3. Filtering out past birthdays and
converting datetime dates to unix timestamps. */
SELECT
id,
UNIX_TIMESTAMP(birthday_date) AS birthday
FROM (
/* Stage 2. Getting this year birthdays */
SELECT
id,
birth_date + INTERVAL (YEAR(CURDATE()) - YEAR(birth_date)) AS YEAR birthday_date
FROM (
/* Stage 1. Converting unix timestamps to datetime values. */
SELECT
id,
FROM_UNIXTIME(birth) AS birth_date
FROM member
) m
) m
WHERE NOW() < birthday_date
关于sql - 如何将出生日期从字段时间戳转换为当年的生日?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5192007/
抱歉我的英语不好......我尝试使用 Google Apps 脚本 - 通讯录服务读取通讯录中的信息。 姓名、电子邮件、地址、电话没有问题,但我无法读取日期(我想获取联系人的出生日期)。如何读取“日
我有一个包含字段生日(DATE) 的用户表。 目前,我像这样选择生日在当前日期之前或之后 7 天内的用户: SELECT * FROM users WHERE DATE_FORMAT(birt
我是一名优秀的程序员,十分优秀!