Link to home
Start Free TrialLog in
Avatar of morinia
moriniaFlag for United States of America

asked on

Converting a date time date to ddmmyyyyformat

I am reading a table using PROC SQL from a SQL Server database.  The DOB field is coming in datetime format.  

I would like to convert 02FEB1951:00:00:00.000    to     02FEB1951
Avatar of MSSystems
MSSystems
Flag of South Africa image

declare @date datetime
set @date = '02FEB1951'

select @date as [Original Date]
, convert(varchar(10), @date, 106) as [dd mon yy]
, replace(convert(varchar(10), @date, 6), ' ', '') as [Requested format]
ASKER CERTIFIED SOLUTION
Avatar of Aloysius Low
Aloysius Low
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can use the following in your code

SELECT REPLACE(CONVERT(VARCHAR(11), <fieldName>,106), ' ', '') AS [DDMonYYYY]