wizard1923
Technical User
just need help converting date from yyyymmdd to yyyy-mm-dd so i can compare two fields with different date formats
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
SELECT [Date1] = CONVERT(DATE, '17760704', 101)
SELECT [Date1] = CAST('17760704' AS DATE);
Declare @MyTable Table (
PK int,
COLUMN1 Varchar(10),
COLUMN2 Varchar(10),
DATE_COLUMN1 VarChar(10),
DATE_COLUMN2 VarChar(10) )
Insert INTO @MyTable (PK, COLUMN1, COLUMN2,DATE_COLUMN1, DATE_COLUMN2 )
Values (1,'John','Smith','01-01-2011','20110115')
Insert INTO @MyTable (PK, COLUMN1, COLUMN2,DATE_COLUMN1, DATE_COLUMN2 )
Values (2,'Terry','Kriten','02-01-2011','20110210')
Insert INTO @MyTable (PK, COLUMN1, COLUMN2,DATE_COLUMN1, DATE_COLUMN2 )
Values (3,'Merry','Xmas','05-17-2011','20110520')
SELECT
PK,
COLUMN1,
COLUMN2,
CAST(DATE_COLUMN1 AS DATETIME),
CAST(DATE_COLUMN2 AS DATETIME),
DATEDIFF(DAY,DATE_COLUMN1,DATE_COLUMN2) As 'Difference in Days'
FROM @MyTable
WHERE DATEDIFF(DAY,DATE_COLUMN1,DATE_COLUMN2) > 10