user3607869
user3607869

Reputation: 315

Mysql previous date

I am using the following to have previous date data at 00.00.00

select * from perf where timeStamp="SUBDATE(CURDATE(),1)";

But this is not resulting any output

where as

select * from perf where timeStamp="2014-11-28";

resulting the proper output

Can anyone of you please help me in trying to find out the issue.Any help is greatly appreciated.

Upvotes: 4

Views: 4406

Answers (3)

Saharsh Shah
Saharsh Shah

Reputation: 29051

Check SUBDATE() function

Try this:

SELECT * 
FROM perf
WHERE DATE(timeStamp) = SUBDATE(CURDATE(), INTERVAL 1 DAY);

Upvotes: 3

baao
baao

Reputation: 73211

timeStamp="SUBDATE(CURDATE(),1)";

Searches for the string "SUBDATE(CURDATE(),1)" and subdate is wrong executed

remove the " " and it should work like the following:

select * from perf where timeStamp= SUBDATE(CURDATE(),INTERVAL 1 DAY);

Upvotes: 0

Girish
Girish

Reputation: 12117

1st no need to quote on SUBDATE() function and, you need to subtract 1 day

select * from perf where timeStamp=SUBDATE(CURDATE(),1);

//or with details of input interval like HOURS, 'DAY', 'MONTH' etc

select * from perf where timeStamp=SUBDATE(CURDATE(),INTERVAL 1 DAY);

Upvotes: 0

Related Questions