I have a varchar
column where some values are in mm/dd/yyyy
format and some are in yyyymmdd
.
I want to convert all mm/dd/yyyy
dates into the yyyymmdd
format. What is the best way to do this? Thanks
Table is Employees
and column is DOB
Convert Char 'yyyymmdd' back to Date data types in SQL Server. Now, convert the Character format 'yyyymmdd' to a Date and DateTime data type using CAST and CONVERT. --A. Cast and Convert datatype DATE: SELECT [CharDate], CAST([CharDate] AS DATE) as 'Date-CAST', CONVERT(DATE,[CharDate]) as 'Date-CONVERT' FROM [dbo].
Assuming your "date" column is not actually a date.
Select convert(varchar(8),cast('12/24/2016' as date),112)
or
Select format(cast('12/24/2016' as date),'yyyyMMdd')
Returns
20161224
DECLARE @v DATE= '3/15/2013' SELECT CONVERT(VARCHAR(10), @v, 112)
you can convert any date format or date time format to YYYYMMDD with no delimiters
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