Wednesday, June 27, 2007

[SQL] Conversion DateTime DataType

Syntax for CAST:
CAST ( expression AS data_type [ (length ) ])

Syntax for CONVERT:
CONVERT ( data_type [ ( length ) ] , expression [ , style ] )
Example:

Format Date to mm/dd/yyyy
CONVERT(nvarchar(11),[FieldName],101)

From: '2007-05-04 16:35:52.140'
To: '05/04/2007'

Reseting Time Value to Zero
CAST(CONVERT(nvarchar(11),[FieldName],101) as datetime)

From: '2007-05-04 16:35:52.140'
To: '2007-05-04 00:00:00.000'


No comments: