How do I name the output textfile to YYYYMMDD based on the system date?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 14:31:19

问题


How do I name the output textfile to YYYYMMDD based on the system date?

sqlcmd -S DataBBB -i c:\scripts\followup.sql
    -o %DATE:~4,2%_%DATE:~7,2%_%DATE:~-4%.txt -s ; -W -u

Now the output text file is 01_31_2012.txt. How can I change it to 2012_01_31.txt?


回答1:


Tried it under Windows 7 Premium (German), may be dependent upon OS and Local Time Format.

sqlcmd -S DataBBB -i c:\scripts\followup.sql 
                            -o %date:~-4%_%date:~3,2%_%date:~0,2%.txt -s; 

You have to edit this part for your system

%date:~-4%_%date:~3,2%_%date:~0,2%.txt

The statement used the command line internal %date% - variable with the extension :~start,length. So you can create the filename with different parts from the date- variable.



来源:https://stackoverflow.com/questions/9074407/how-do-i-name-the-output-textfile-to-yyyymmdd-based-on-the-system-date

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!