I am trying to select the DeliveryDate from sql database as just date. In the database, i am saving it as datetime format. How is it possible to get just date??
SELECT Subject, DeliveryDate
from Email_Administration
where MerchantId =@ MerchantID
03/06/2011 12:00:00 Am just be selected as 03/06/2011..
Thanks alot in advance! :)
This question is related to
sql
sql-server
sql-server-2005
datetime
With SQL server you can use this
SELECT CONVERT(VARCHAR(10), GETDATE(), 101) AS [MM/DD/YYYY];
with mysql server you can do the following
SELECT * FROM my_table WHERE YEAR(date_field) = '2006' AND MONTH(date_field) = '9' AND DAY(date_field) = '11'
if you are using SQL Server use convert
e.g. select convert(varchar(10), DeliveryDate, 103) as ShortDate
more information here: http://msdn.microsoft.com/en-us/library/aa226054(v=sql.80).aspx
SELECT Subject, CONVERT(varchar(10),DeliveryDate) as DeliveryDate
from Email_Administration
where MerchantId =@ MerchantID
try the following as there will be no varchar conversion
SELECT Subject, CAST(DeliveryDate AS DATE)
from Email_Administration
where MerchantId =@ MerchantID
Source: Stackoverflow.com