Author Options:

Is there a batch script that you can compile and have it run a command when a date/time is met. Answered

I need a batch script that can: run in the backround when a certain date/time is reached execute a command Any help would be much appreciated. Private Message me Thanks dla888



This should work...

If %date%==YOURDATEHERE (mm/dd/yyyy) goto time
goto date
goto time

Place this in your startup folder and it will run in the background.


8 years ago

Use this: <br /> @echo off<br /> :X<br /> if date==*your date here* *what you wanna do here*<br /> goto X<br /> <br /> save as whatyouwannauseasname.bat & put on startup<br /> DONE!<br />


9 years ago

The following biterscripting ( http://www.biterscripting.com ) batch script will do it. It will wait until it is June 11, 1009, 2:30 pm, then execute command "command".

while ( gettime() < "20090611143000")
system "command"


As a straight batch file, Windows gives you Too Much Information to do this . . .
Type in 'echo %date%' (without the quotes) and press Enter.
The date is displayed.
Now type in '%time%'
The time is displayed, but to a resolution of 1/1000th of a second!
You can use comparison operators in batch files, but there's no way (that I know of) of masking out part of the %time% string so you could compare, but you'd probably miss the event!

A better way of doing what you want is to use the built-in scheduler. To get to this, go to Control Panel then Scheduled Tasks. You can run any program you like (including batch files) from there.

You can also set up the scheduler from a batch file, which is closer to what you're after. It can run once, or every hour, week etc. You need to use the AT command, so your set-up batch would be something like :
This would run your batch file (mybatch) at 2:20 PM on the 25th of the month.

there's no way (that I know of) of masking out part of the %time% string
try echo %time:~0,8% or echo %time:~0,5%.

Wow! Live and learn! As it's part of the TIME system variable, is this an undocumented parameter or can it be used more widely?

It can be used with any variable, with the exception of %1, %2, etcetera.
Also try ...
set variable=123abc
echo %variable:abc=456%

You're a scary thirteen year old, Padlock ;¬)
Many thanks - I'll be using that in the future.

I've just seen your avatar - We are talking Windows here aren't we ? (not Linux ;¬)

I would love to go fully linux but I have many windows files and I'm probably going to need to know it because so much of the world runs on it. So I figure I should learn both.

I started wayyyyy back with a couple of the first (pre IBM) desktop computers and then onto my first PC (an XT) with MSDOS, and started on Windows at version 3.0. I've played with a few flavours of Linux (Puppy, Mint) but I have so many Windows applications and utilities for doing the things I do that it would take months to get anything equivalent going in Linux - if at all. Linux remains a bit of fun for me (but it has helped me on more than once occasion by booting up from a memory stick and accessing hard drives which Windows had given up on.)

Batch files have their limitations you know. A batch file is a batch of commands, it's not a programming language. At some point you'll have to stop asking "how do I do this with a batch?" and just ask "how do I do this?" Visual Basic? L

Visual Basic sounds good to start with. I think I'll try that.

Best wishes for it, I know there's quite a lot of VB resources about. L