Taking Database backup: How to skip '/' from getdate so that it is not considered to be in a folder
-
30-09-2019 - |
Question
I am trying to take database backup. How can I do that when getdate is being appended with file name with format dd/mm/yyyy.
declare @dbName VARCHAR(100)
declare @path VARCHAR(100)
set @dbName='CallMeIndia'
set @path='F:\'+@dbName +'-'+convert(varchar(50),getdate(),103)+'.bak'
BACKUP DATABASE @dbName
TO DISK= @path
Solution
@Shantanu, a file can't include the /
char in the name , try using another format, something like yyyymmdd (112) , you can check this link for more formats.
set @path='F:\'+@dbName +'-'+convert(varchar(50),getdate(),112)+'.bak'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow