I\'m using the below to backup a db from a SQL job. Can someone tell me how to add the current date to the output filename? Preferably in YYYYMMDD format.
BACK
DECLARE @var nvarchar(max) ='C:\Projects\myDatabase ' +replace(rtrim(convert(char,getdate())), ':',',')+'.bak'; BACKUP DATABASE myDatabase TO DISK = @var
output:
C:\Projects\myDatabase Jun 3 2015 6,33AM.bak