How to get DATE from DATETIME Column in SQL?
date, datetime, sql, sql-server
Solution
Simply cast your timestamp `AS DATE`, like this:
SELECT CAST(tstamp AS DATE)
SQLFiddle Demo
In other words, your statement would look like this:
SELECT SUM(transaction_amount)
FROM mytable
WHERE Card_No='123'
AND CAST(transaction_date AS DATE) = target_date
What is nice about `CAST` is that it works exactly the same on most SQL engines (SQL Server, PostgreSQL, MySQL), and is much easier to remember how to use it. Methods using `CONVERT()` or `TO_DATE()` are specific to each SQL engine and make your code non-portable.
Problem
I have 3 columns in Table TransactionMaster in sql server 1) transaction_amount 2) Card_No 3) transaction_date-- `datetime` datatype So, I want to fetch SUM of `transaction_amount where Card_No=' 123'` and `transaction_date= todays date`.<----- excluding time IN SQL