none
Rename a file to date and timestamp RRS feed

  • Question

  • I don't know if this is the right forum for this question or not.  I have a SQL job that produces a text file and I am trying to rename the file with a date and timestamp.

     

    For example, the file is named 'test.txt' I want the file to be renamed to '20080418.txt'

     

    Thanks,

    Nick

     

    Friday, April 18, 2008 12:54 PM

Answers

  • WHat is the error you gets?  Post back the error . 

     

    you may do something like this

     

    Declare @dt datetime ,@SQLstmt varchar(100)

    Set @dt=getdate()

    set @SQLstmt ='RENAME c:\text.txt '+convert(varchar(15),@dt,112)+'.txt'

    print @SQLstmt

    exec xp_cmdshell @SQLstmt

     

    Madhu
    Saturday, April 19, 2008 11:03 AM
    Moderator

All replies