# How to execute a cmd file based on time?



## sotando (Mar 2, 2011)

Hello All,

I have a cmd file that works, and what I want to do is execute the cmd file based on a time.

*This works:*

@echo off
echo NCR_EDB SSIS Package Start
set SSIS_HOME="C:\Program Files\Microsoft SQL Server\100\DTS\Binn"
cd %SSIS_HOME%
"e:\Program Files\Microsoft SQL Server\100\DTS\Binn\dtexec" /f "e:\DCIU\Package\Process DCIU_Prod.dtsx" /REPORTING EDP >e:\DCIU_bat.log


*This does not work:*

IF '%TIME%' between 01:00 and 8:00 
(
@echo off
echo NCR_EDB SSIS Package Start
set SSIS_HOME="C:\Program Files\Microsoft SQL Server\100\DTS\Binn"
cd %SSIS_HOME%
"e:\Program Files\Microsoft SQL Server\100\DTS\Binn\dtexec" /f "e:\DCIU\Package\Process DCIU_Prod.dtsx" /REPORTING EDP >e:\DCIU_bat.log
) 
ELSE 
(exit)

Does anyone know the IF Else with the %TIME% not working? 

Please advice.

Thanks.


----------



## TheOutcaste (Aug 8, 2007)

The line continuation has to be on the same line as the *If* and/or *Else* statement.
The output format of the *%time%* variable may vary depending on your regional settings. It usually includes seconds and hundredths of seconds.
It may include a leading space instead of a leading 0, it may be in AM/PM format rather than 24 hour time.
It might also be different depending on which version of Windows you are running. US English uses leading space and 24 hour format, and is the same on XP and later, but I've not tested all regional settings to see if they are consistent between different versions of Windows.

You need something like this, assuming 24 hour format with a leading space instead of leading 0:

```
@Echo Off
If "%time%" LSS " 8:00:00.00" (
  If "%time%" GTR " 1:00:00.00" (
[SIZE=3][FONT=Times New Roman]      echo NCR_EDB SSIS Package Start[/FONT][/SIZE]
     [SIZE=3][FONT=Times New Roman]set SSIS_HOME="C:\Program Files\Microsoft SQL Server\100\DTS\Binn"[/FONT][/SIZE]
     [SIZE=3][FONT=Times New Roman]cd %SSIS_HOME%[/FONT][/SIZE]
     [SIZE=3][FONT=Times New Roman]"e:\Program Files\Microsoft SQL Server\100\DTS\Binn\dtexec" /f "e:\DCIU\Package\Process DCIU_Prod.dtsx" /REPORTING EDP >e:\DCIU_bat.log[/FONT][/SIZE]
  )
)
```


----------

