MySQL selecting yesterday’s date

SELECT SUBDATE(NOW(),1);

where now() function returs current date and time of system in Timestamp…

you can use:

SELECT SUBDATE(CURDATE(),1)

使用下面這 2個句子,都可以取得當天 00:00 時的資料:

select DATE(now());

select SUBDATE(CURDATE(),0);

 


In MySQL:

SELECT  *
FROM    mytable
WHERE   record_date >= CURDATE() - INTERVAL 1 DAY

In SQL Server:

SELECT  *
FROM    mytable
WHERE   record_date >= DATEADD(day, -1, GETDATE())

In Oracle:

SELECT  *
FROM    mytable
WHERE   record_date >= SYSDATE - 1

In PostgreSQL:

SELECT  *
FROM    mytable
WHERE   record_date >= NOW() - '1 day'::INTERVAL

In Redshift:

SELECT  *
FROM    mytable
WHERE   record_date >= GETDATE() - '1 day'::INTERVAL

In SQLite:

SELECT  *
FROM    mytable
WHERE   record_date >= datetime('now','-1 day')

In MS Access:

SELECT  *
FROM    mytable
WHERE   record_date >= (Now - 1)

 

 

 

相關文章

寫留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *