Relative date to start a scheduled task

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
david.lynch
Posts: 13
Joined: 08 Jul 2012 21:00

Relative date to start a scheduled task

#1 Post by david.lynch » 08 Jul 2012 21:08

Hello everyone! Image

I'm looking for a batch script that would schedule a task to start 40 days from now (so, it is a relative date).

It should be language independent and compatible with XP/Vista/2008/7, x86 and x64.

Any help would be greatly appreciated!

Image

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

Re: Relative date to start a scheduled task

#2 Post by foxidrive » 09 Jul 2012 00:25

VBS can get a date 40 days hence

The AT.EXE command might be able to take a date.


Code: Select all

:: Date foward & backward
@echo off
:: from code by Phil Robyn
setlocal
if [%1]==[] (
  echo to get todays date use
  echo call "%~n0" today 0
  echo.
  echo to get yesterdays date use
  echo call "%~n0" today -1
  echo.
  echo to get the date 25 days ago:
  echo call "%~n0" today -25
  echo.
  echo to get the date 1250 days in the future
  echo call "%~n0" today +1250
  goto :EOF)

set date1=%1
set qty=%2
if /i "%date1%" EQU "TODAY" (
 set date1=now
) else (
 set date1="%date1%"
)
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%qty%,%date1%)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_
echo>>"%temp%\%~n0.vbs"         right(100+month(s),2)^&_
echo>>"%temp%\%~n0.vbs"         right(100+day(s),2)
for /f %%a in (
  'cscript //nologo "%temp%\%~n0.vbs"') do set result=%%a
del "%temp%\%~n0.vbs"
endlocal& set day=%result:~0,4%-%result:~4,2%-%result:~6,2%
echo %%day%% is set to "%day%" (without the quotes)

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Relative date to start a scheduled task

#3 Post by Aacini » 09 Jul 2012 08:46

You may use my StdDate.exe program to get the future date in a very easy way:

Code: Select all

StdDate > NUL
set /A future=%errorlevel%+40
StdDate %future%

david.lynch
Posts: 13
Joined: 08 Jul 2012 21:00

Re: Relative date to start a scheduled task

#4 Post by david.lynch » 09 Jul 2012 11:35

Hello, when I try to use the HexToBin it generates a StdDate.exe of 0 bytes...

What could be wrong?

Image

Aacini wrote:You may use my StdDate.exe program to get the future date in a very easy way:

Code: Select all

StdDate > NUL
set /A future=%errorlevel%+40
StdDate %future%

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Relative date to start a scheduled task

#5 Post by Aacini » 09 Jul 2012 16:29

I don't know. Did you also copied HexChar.vbs file?

Code: Select all

>dir
 Volume in drive C has no label.
 Volume Serial Number is CCA1-5338

 Directory of C:\Documents and Settings\Antonio\My Documents\ASMB\Batch File Programming\tests\test

09/07/2012  05:20 p.m.    <DIR>          .
09/07/2012  05:20 p.m.    <DIR>          ..
09/07/2012  05:21 p.m.               686 HexChar.vbs
09/07/2012  05:20 p.m.               515 HexToBin.bat
09/07/2012  05:18 p.m.             2,881 StdDate.exe.hex
               3 File(s)          4,082 bytes
               2 Dir(s)   1,856,012,288 bytes free

C:\Documents and Settings\Antonio\My Documents\ASMB\Batch File Programming\tests\test
>hextobin StdDate.exe.hex
StdDate.exe file created
C:\Documents and Settings\Antonio\My Documents\ASMB\Batch File Programming\tests\test
>dir
 Volume in drive C has no label.
 Volume Serial Number is CCA1-5338

 Directory of C:\Documents and Settings\Antonio\My Documents\ASMB\Batch File Programming\tests\test

09/07/2012  05:21 p.m.    <DIR>          .
09/07/2012  05:21 p.m.    <DIR>          ..
09/07/2012  05:21 p.m.               686 HexChar.vbs
09/07/2012  05:20 p.m.               515 HexToBin.bat
09/07/2012  05:21 p.m.             3,072 StdDate.exe
09/07/2012  05:18 p.m.             2,881 StdDate.exe.hex
               4 File(s)          7,154 bytes
               2 Dir(s)   1,856,008,192 bytes free

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

Re: Relative date to start a scheduled task

#6 Post by foxidrive » 09 Jul 2012 17:51

Aacini, you could have a single post with one batch file that creates all your utilities. Make it easy for people and they will use them.

I suggested this before and you ignored me: I know that it's a PITA trying to extract the information for one tool, let alone all of them - and you're making it hard for people to use all your tools. That's illogical, if you want your programs to become widely used.

After all - this is a batch file site and we use batch file to make our tasks easier. What better way is there to create all your tools in one hit?

david.lynch
Posts: 13
Joined: 08 Jul 2012 21:00

Re: Relative date to start a scheduled task

#7 Post by david.lynch » 09 Jul 2012 20:39

I was missing the .vbs. It worked perfectly Image but how could I set a variable with StdDate result on the same batch?

Thank you for taking the time to write all those tools. Small, fast, compatible and really helpful.


Image & Image

Image

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Relative date to start a scheduled task

#8 Post by Aacini » 10 Jul 2012 07:43

david.lynch wrote:... how could I set a variable with StdDate result on the same batch?

Use a FOR /F command this way:

Code: Select all

StdDate > NUL
set /A future=%errorlevel%+40
for /F %%a in ('StdDate %future%') do set futureDate=%%a


Antonio

david.lynch
Posts: 13
Joined: 08 Jul 2012 21:00

Re: Relative date to start a scheduled task

#9 Post by david.lynch » 10 Jul 2012 08:47

Great! Image

Image

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Relative date to start a scheduled task

#10 Post by Aacini » 10 Jul 2012 09:48

foxidrive wrote:... you're making it hard for people to use all your tools.

I don't think so. David just misread the beginning of the explanation about how to create my .exe auxiliary programs:
Aacini wrote:NOTE: If you want to convert a filename.exe.hex file to filename.exe, just copy both HexToBin.bat and HexChar.vbs files below, and type: hextobin filename.exe.hex


foxidrive wrote:Aacini, you could have a single post with one batch file that creates all your utilities...

I suggested this before and you ignored me: I know that it's a PITA trying to extract the information for one tool...

After all - this is a batch file site and we use batch file to make our tasks easier. What better way is there to create all your tools in one hit?


You should realize that each one of these programs have its own description and examples, and its number increase as I release they. I think it will be harder for people to download the complete set of programs, descriptions and examples if they just want one program! The example of that is David in this topic: why he should download a file about 15 times larger if he just wanted to use StdDate program?

What is needed is an index at the beginning of that topic so people may quickly browse the auxiliary programs and easily locate the specific one(s) they wants. I will post that index soon.

However, if your concerns about "Make it easy for people ... use" my programs are genuine and not just an opportunity to criticize (that you are prone to), why you don't write the Batch file you suggested yourself? As you know, write that Batch file is easy: you just need to compile the information I posted in two topics! This way, the Batch file will be completed in exactly the way you want. So?

Antonio

PS - I apologize for "ignored you" in the past, but I was very busy writting the auxiliary programs...

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Relative date to start a scheduled task

#11 Post by Squashman » 10 Jul 2012 11:25

Slightly off topic but some what related to Foxi's point, I use a utility called Swiss File Knife. It is one single command line utility that does a whole lot of tasks. It combines many functions into a single executable. You could do the same with all your utilities.

http://stahlworks.com/dev/swiss-file-knife.html

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Relative date to start a scheduled task

#12 Post by Aacini » 10 Jul 2012 12:37

That is precisely the opposite point of view of my program design! If you read my previous, old posts, perhaps you remember that I started these utilities with small .com executable files of a couple hundred bytes sizes. When I was forced to write Win32 .exe executable files, I complained about the new size of the same programs, about 1500-2000 bytes. Why is small size an important point here? Because Batch file execution is SLOW! If the auxiliary program is large, then Batch programs like Mandelbrot Set in color or the animated game Snake, that execute the auxiliary file hundred or thousand times, would be just too slow to be useful...

EDIT: As a matter of fact, in my opinion the only way that Batch may achieve some tasks normally deserved to any other real programming language is by trying to write Batch programs that run in the fastest possible way, and the only way to do that with additional Batch features is via the smallest possible auxiliary files!

david.lynch
Posts: 13
Joined: 08 Jul 2012 21:00

Re: Relative date to start a scheduled task

#13 Post by david.lynch » 10 Jul 2012 12:50

Aacini wrote:David just misread the beginning of the explanation about how to create my .exe auxiliary programs:


That's true, I was really tired, almost sleeping on the PC Image

Aacini wrote:What is needed is an index at the beginning of that topic so people may quickly browse the auxiliary programs and easily locate the specific one(s) they wants. I will post that index soon.


I agree!

Please keep your tools coming. Great work, and it is appreciated Image

Peace!

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Relative date to start a scheduled task

#14 Post by Squashman » 10 Jul 2012 13:09

Aacini wrote:That is precisely the opposite point of view of my program design! If you read my previous, old posts, perhaps you remember that I started these utilities with small .com executable files of a couple hundred bytes sizes. When I was forced to write Win32 .exe executable files, I complained about the new size of the same programs, about 1500-2000 bytes. Why is small size an important point here? Because Batch file execution is SLOW! If the auxiliary program is large, then Batch programs like Mandelbrot Set in color or the animated game Snake, that execute the auxiliary file hundred or thousand times, would be just too slow to be useful...

EDIT: As a matter of fact, in my opinion the only way that Batch may achieve some tasks normally deserved to any other real programming language is by trying to write Batch programs that run in the fastest possible way, and the only way to do that with additional Batch features is via the smallest possible auxiliary files!

Well Swiss File Knife is so small it fits on a Floppy Disk and has about 90 utilities built-in to it. And it is wicked fast at doing some of the Large Data Processing I need it to do. I used to have a pure batch solution for appending data to the end of each line in very large text files. Pure batch was extremely slow but SFK was super fast at doing it.

I was just making an observation based on my experience with another piece of software.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Relative date to start a scheduled task

#15 Post by Aacini » 10 Jul 2012 18:26

Squashman wrote:Well Swiss File Knife is so small it fits on a Floppy Disk and has about 90 utilities built-in to it. And it is wicked fast at doing some of the Large Data Processing I need it to do. I used to have a pure batch solution for appending data to the end of each line in very large text files. Pure batch was extremely slow but SFK was super fast at doing it.

I was just making an observation based on my experience with another piece of software.


Yes, my first answer was also based on what I think it would happen with a big program. It seems that the only way to answer this question is to do a simple test. Perhaps you may take one of the Batch files I mentioned above (Mandelbrot Set or Snake, or anyone you wish with heavy repetitive loops) and insert a simple call to Swiss File Knife (sfk > nul) in the innermost loop. If the additional running time is not significant, then the suggestion of grouping all my programs in one big file will seem a good idea (and I will thank you for it)!

Post Reply