My datetime field is in date format M/dd/yyyy. SQL Server date is in date format yyyy-mm-dd. I need to get the current date -7 days and format the output
Example.
SELECT * FROM [Table]
WHERE Time Generated >= current date - 7 days
Output of current date - 7 should be M/dd/yyyy
SELECT FORMAT(Getdate(), 'MM dd, yyyy')
DECLARE @date varchar(30) = FORMAT(getdate(), 'M/dd/yyyy');
SELECT Computer, AppFileDisplayName FROM DHAppReliability
WHERE HasCrashesDaily = 'TRUE'
AND TimeGenerated <= DATEADD(DAY, -7, @date)
ORDER BY Computer
Msg 241, Level 16, State 1, Line 2 Conversion failed when converting date and/or time from character string.