如何从数据库中获取今天添加的记录?

时间:2017-04-25 07:56:20

标签: mysql

我在数据库中添加了记录,其中创建日期存储在时间戳值中。 time()值。但现在我想获取今天添加的所有记录。我被卡住并搜索谷歌但未找到。

SELECT  id,COUNT(*) as total,
                   SUM(CASE WHEN DATE( `tsCreated` ) =  CURDATE() then 1 else 0 end) as todays
                   FROM  products

2 个答案:

答案 0 :(得分:1)

SELECT id,COUNT(*) FROM `products` WHERE DATE(`tsCreated`) = CURDATE()

答案 1 :(得分:0)

如果你想现在获得日期,那么其他0:

SELECT id,CASE WHEN DATE(`tsCreated`) =  date(CURDATE()) then 1 else 0 end as todays 
FROM  products 

如果你想计算tsCreated =现在:

SELECT count(1) as total
FROM  products  where DATE(`tsCreated`) =  date(CURDATE())