Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL query to show data by today(current) date?

I am trying to get the record from database with current date only here is the query I have tried bu getting no records from table:

SELECT *
FROM Transactions
WHERE transaction_date = GETDATE(); 
like image 473
Kamran Ashiq Avatar asked Jan 30 '23 18:01

Kamran Ashiq


2 Answers

It's the current date, so the records with future dates don't exist. You just need to get all transactions greater than 00:00:00 of today.

SELECT * FROM `Transactions` WHERE transaction_date >= CURRENT_DATE+" 00:00:00";
like image 179
Hackinet Avatar answered Feb 01 '23 18:02

Hackinet


Just compare the date part

   Select *from Transactions
        WHERE 
    CONVERT(char(10), transaction_date  ,126)=CONVERT(char(10), getdate(),126);
like image 31
Ranjana Ghimire Avatar answered Feb 01 '23 17:02

Ranjana Ghimire