Nov 20, 2012

CONVERT DATE AND TIME THEN CAST

11/20/2012 08:49:00 PM

CONVERT DATE AND TIME



SELECT CONVERT(VARCHAR(30),GETDATE()) AS DateConvert;
SELECT CONVERT(VARCHAR(30),GETDATE(),10) AS DateConvert;--mm-dd-yy
SELECT CONVERT(VARCHAR(30),GETDATE(),110) AS DateConvert;--mm-dd-yyyy
SELECT CONVERT(VARCHAR(30),GETDATE(),5) AS DateConvert;--dd-mm-yy
SELECT CONVERT(VARCHAR(30),GETDATE(),105) AS DateConvert;--dd--mm-yyyy
SELECT CONVERT(VARCHAR(30),GETDATE(),113) AS DateConvert;--dd-mon-year 'hh:mm:ss:mmm',
SELECT CONVERT(VARCHAR(30),GETDATE(),114) AS DateConvert;--'hh:mm:ss:mmm'

Differend Between CAST vs CONVERT
USE AdventureWorks2008R2

--Use CONVERT
select CONVERT(VARCHAR(10),BusinessEntityID) FROM HumanResources.Employee 
--Use CAST
select CAST(BusinessEntityID AS VARCHAR(10)) FROM HumanResources.Employee





Note:
When we move to the properties for the query using the CAST operation, we see that under the hood, SQL Server does take us for a ride. Internally, CAST is implemented as a CONVERT call. There is no difference between CAST & CONVERT besides the fact that CAST is an ANSI standard, while CONVERT is not. No wonder both CAST & CONVERT demonstrate the same performance.



Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 comments:

Post a Comment

Recent Posts
Popular Articles

 

© 2013 MUNISH ORACLE DBA& .Net Developer. All rights resevered. Designed by Templateism

Back To Top