Steve A
asked on
Date not Formatting to YYYYMMDD
Hello,
I have a field that I want to convert to a format of YYYYMMDD and going with this scenario, it gives me a date of '04/18/19'
Declare @MemberDOB nvarchar(10)
Set @MemberDOB = '04/18/1960'
Select Convert(VarChar(8), @MemberDOB, 112)
I want it to be '19600418', but it doesn't. (table uses nvarchar, and cannot be changed to another datatype initially)
Any Clues?
Thanks
I have a field that I want to convert to a format of YYYYMMDD and going with this scenario, it gives me a date of '04/18/19'
Declare @MemberDOB nvarchar(10)
Set @MemberDOB = '04/18/1960'
Select Convert(VarChar(8), @MemberDOB, 112)
I want it to be '19600418', but it doesn't. (table uses nvarchar, and cannot be changed to another datatype initially)
Any Clues?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay,
Thanks for the replies.
I tried this and seems to work:
Declare @MemberDOB nvarchar(10)
Set @MemberDOB = '04/18/1960'
Select Convert(VarChar(8), Cast(@MemberDOB As DateTime), 112)
Thanks for the replies.
I tried this and seems to work:
Declare @MemberDOB nvarchar(10)
Set @MemberDOB = '04/18/1960'
Select Convert(VarChar(8), Cast(@MemberDOB As DateTime), 112)
Declare @MemberDOB nvarchar(10)
Set @MemberDOB = '04/18/1960'
SELECT cast(datepart(year, @MemberDOB) as sysname) + cast(datepart(month, @MemberDOB) as sysname) + cast(datepart(day, @MemberDOB) as sysname);