Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL datetime format to date only

Tags:

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! :)

like image 386
challengeAccepted Avatar asked Mar 07 '11 16:03

challengeAccepted


People also ask

How can I get only the date from DateTime?

ToString() − One more way to get the date from DateTime is using ToString() extension method. The advantage of using ToString() extension method is that we can specify the format of the date that we want to fetch. DateTime. Date − will also remove the time from the DateTime and provides us the Date only.

How do I get only the date in SQL without time?

However, if you want to get just the current date – not the date and the time – you can use the CAST() function. This function takes any expression or any column name as the first argument. Then you use the keyword AS and enter the new data type to return.

How do I print only the date in SQL?

SELECT CONVERT(VARCHAR(10),GETDATE(),101) is mm/dd/yyyy format.


2 Answers

After perusing your previous questions I eventually determined you are probably on SQL Server 2005. For US format you would use style 101

select Subject,         CONVERT(varchar,DeliveryDate,101) as DeliveryDate from Email_Administration  where MerchantId =@MerchantID  
like image 113
Martin Smith Avatar answered Dec 03 '22 06:12

Martin Smith


try the following as there will be no varchar conversion

SELECT Subject, CAST(DeliveryDate AS DATE) from Email_Administration  where MerchantId =@ MerchantID 
like image 43
efatihan Avatar answered Dec 03 '22 05:12

efatihan