How to get the Previous Sunday date based on current date in batch file. For getting current date i am using this...
echo %date:~-3,2%\%date:~7,2%\%date:~10,4%
How to get the Previous Sunday date based on current date in batch file. For getting current date i am using this...
echo %date:~-3,2%\%date:~7,2%\%date:~10,4%
@if (@x)==(@y) @end /***** jscript comment ******
@echo off
for /f "delims=" %%d in ('cscript //E:JScript //nologo "%~f0"') do set "p_sund=%%d"
echo %p_sund%
exit /b 0
***** end comment *********/
var beforeOneWeek = new Date(new Date().getTime() - 60 * 60 * 24 * 7 * 1000)
, day = beforeOneWeek.getDay()
, diffToMonday = beforeOneWeek.getDate() - day + (day === 0 ? -6 : 1)
, lastMonday = new Date(beforeOneWeek.setDate(diffToMonday))
, lastSunday = new Date(beforeOneWeek.setDate(diffToMonday + 6));
WScript.Echo(beforeOneWeek);
EDIT in case the windows script host exe is disabled the mshta cab be used:
@if (@x)==(@y) @end /***** jscript comment ******
@echo off
for /f "delims=" %%d in ('cscript //E:JScript //nologo "%~f0"') do set "p_sund=%%d"
rem echo %p_sund%
Echo ^<html^>^<head^>>"temp.hh"
Echo ^<hta:application windowstate="minimize"^>>>"temp.hh"
Echo ^<script type="text/jscript" src="%~nx0"^>>>"temp.hh"
Echo ^</script^>^</head^>^</html^>>>"temp.hh"
Mshta.exe "temp.hh"
type temp.res
del /q /f "temp.hh" ""temp.res"" >nul 2>&1
exit /b 0
***** end comment *********/
var beforeOneWeek = new Date(new Date().getTime() - 60 * 60 * 24 * 7 * 1000)
, day = beforeOneWeek.getDay()
, diffToMonday = beforeOneWeek.getDate() - day + (day === 0 ? -6 : 1)
, lastMonday = new Date(beforeOneWeek.setDate(diffToMonday))
, lastSunday = new Date(beforeOneWeek.setDate(diffToMonday + 6));
WScript.Echo(beforeOneWeek);
var objFSO=new ActiveXObject("Scripting.FileSystemObject");
var outFile="temp.res";
var objFile = objFSO.CreateTextFile(outFile,true);
objFile.Write(beforeOneWeek);
objFile.Close();
later will think about powershell solution.