get date 1 day ago

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
izy
Posts: 43
Joined: 29 May 2012 13:29

get date 1 day ago

#1 Post by izy » 01 Mar 2016 07:33

How to set script below that use yestarday date (date -1day)?

FOR /F "tokens=2-4delims=. " %%A IN ("%date%") DO (
SET day=%%A
SET month=%%B
SET year=%%C
)
echo FMS_%year%%month%%day%*.txt

echo. ------------------------------------------------------
echo %date% %time% Downloading file from server1
wget --ftp-user=%username1% --ftp-password=%password1% ftp://%server_name1%/%remote_directory1%/FMS_%year%%month%%day%*.txt

(
echo open %server_name2%
echo %username2%
echo %password2%
echo binary
echo cd %remote_directory2%
echo put FMS_%year%%month%%day%*.txt
echo quit
)>list2.ftp
FTP -i -s:list2.ftp

del FMS_%year%%month%%day%*.txt

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: get date 1 day ago

#2 Post by foxidrive » 01 Mar 2016 11:10

Code: Select all

@echo off
:: date yesterday (-1) or any number

set day=-1
(
echo s=DateAdd("d",%day%,now^) : d1=Cstr(weekday(s^)^) : d2=WeekdayName(d1,0^)
echo WScript.Echo Cstr(year(s^)^)+" "+Cstr(right(100+month(s^),2^)^)+" "+Cstr(right(100+day(s^),2^)^)+" "+d1+" "+d2
)>"%temp%\%~n0.vbs"

for /f "tokens=1-5" %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "YYYY=%%a" & set "MM=%%b" & set "DD=%%c" & set "daynum=%%d" & set "weekday=%%e"
del "%temp%\%~n0.vbs"
set "newdate=%YYYY%%MM%%DD%"
echo Using the day offset of %day% it was "%newdate%" at that time,
echo and day number=%daynum% (%weekday%)
pause

Post Reply