How can I use a bat script to return the year, month, and day of yesterday? In fact, it is very troublesome to use bat to write a for to get the year, month, and day of the date, and then write a smallProgramTo calculate the year, month, and day of yesterday. In fact, to enable direct execution of. netCodeGood,. Net datetime. Now. adddays (-1) is yesterday
In fact, powershell will help you answer this question. You can use the rich functions supported by the. NET class library, such as operating XML, file IO, network, and other features. Of course, you can also write a class library to implement complicated scripts.
In this case, open powershell and input [datetime]: Now.
Returns the current date. If you want to see the methods and attributes of now
[Datetime]: Now | get-member
Of course, if you want to calculate how old you are, [datetime]: Now-[datetime] ("yourbirthday") will return your age. I usually use this to calculate my baby for several months.
Powershell allows you to define a variable for FTP download. You can first generate the file name you want to download, sort it into a string, and send it to FTP.
The following is a simple example.
$ Yersterday = [datetime]: Now. adddays (-1 );
$ Yyyy = $ yersterday. Year;
$ Mm = $ yersterday. month;
$ Day = $ yersterday. Day;
$ File1 = [String]: Format ("90193698 _ {0} {}_{ 0} {20..zip", $ yyyy, $ mm, $ Day );
$ Cmd = "Open yourftpserver
User Username Password
Binary
Get $ file1"
$ Cmd | FTP-I-n
Save it as a PS1 file. If you want it to run automatically, write a Windows schedule task "powershell fullpathoftheps1"
By default, poweshell has an execution policy that does not run the file that executes the signature. You can change it
Set-executionpolicy remotesigned
Or change the Registry directly.
HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ powershell \ 1 \ shellids \ microsoft. powershell
Maybe this is a good example of PS.