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! :)
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.
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.
SELECT CONVERT(VARCHAR(10),GETDATE(),101) is mm/dd/yyyy format.
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
try the following as there will be no varchar conversion
SELECT Subject, CAST(DeliveryDate AS DATE) from Email_Administration where MerchantId =@ MerchantID
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With