Solved exit bat file


junieman

Well-known member
Local time
2:37 AM
Posts
53
OS
windows 11 pro
I have a bat file and would like to exit out of it if yesterday's date = SUNDAY OR SATURDAY.
Any other days the bat file would run correctly.
 

My Computer My Computer

At a glance

windows 11 prointel core i7-11700f12 gb
OS
windows 11 pro
Computer type
PC/Desktop
Manufacturer/Model
dell
CPU
intel core i7-11700f
Memory
12 gb
Monitor(s) Displays
3
Hard Drives
256
Keyboard
wireless
Mouse
wireless
Internet Speed
50 mb
In the most general terms, you'd have to look for the DAY-DATA at the very first of the batch file and if it were Saturday or Sunday, then jump to END.
I've written b'zillions of batch files over the past 40 years or so, but I've never done exactly what you want to do.

I do believe it's possible to do what you want in DOS Batch File language, even though I can't give you the exact Syntax.

Good Luck,
TM :cool:
 
I have a bat file and would like to exit out of it if yesterday's date = SUNDAY OR SATURDAY.
Any other days the bat file would run correctly.
This might help

 

My Computer My Computer

At a glance

Windows 11 Pro + Win11 Canary VM.I9 13th gen i9-13900H 2.60 GHZ16 GB solderedIntegrated Intel Iris XE
OS
Windows 11 Pro + Win11 Canary VM.
Computer type
Laptop
Manufacturer/Model
ASUS Zenbook 14
CPU
I9 13th gen i9-13900H 2.60 GHZ
Motherboard
Yep, Laptop has one.
Memory
16 GB soldered
Graphics Card(s)
Integrated Intel Iris XE
Sound Card
Realtek built in
Monitor(s) Displays
laptop OLED screen
Screen Resolution
2880x1800 touchscreen
Hard Drives
1 TB NVME SSD (only weakness is only one slot)
PSU
Internal + 65W thunderbolt USB4 charger
Case
Yep, got one
Cooling
Stella Artois (UK pint cans - 568 ml) - extra cost.
Keyboard
Built in UK keybd
Mouse
Bluetooth , wireless dongled, wired
Internet Speed
900 mbs (ethernet), wifi 6 typical 350-450 mb/s both up and down
Browser
Edge
Antivirus
Defender
Other Info
TPM 2.0, 2xUSB4 thunderbolt, 1xUsb3 (usb a), 1xUsb-c, hdmi out, 3.5 mm audio out/in combo, ASUS backlit trackpad (inc. switchable number pad)

Macrium Reflect Home V8
Office 365 Family (6 users each 1TB onedrive space)
Hyper-V (a vm runs almost as fast as my older laptop)
I have a bat file and would like to exit out of it if yesterday's date = SUNDAY OR SATURDAY.
Any other days the bat file would run correctly.
Why not open Task Scheduler and Create a Task to run the batch file? In the settings for the Task, you can specify Monday to Friday (or NOT saturday or Sunday), and it will run at the time you set M-F, but not on Sa Su.
 

My Computers My Computers

  • At a glance

    11 Pro 24H2 26100.2454i7-9700 @ 3.00GHz32GBDDR4 @ 2666MHzIntel HD 630 Graphics onboard
    OS
    11 Pro 24H2 26100.2454
    Computer type
    PC/Desktop
    Manufacturer/Model
    Lenovo ThinkCentre M920S SFF
    CPU
    i7-9700 @ 3.00GHz
    Motherboard
    Lenovo 3132
    Memory
    32GBDDR4 @ 2666MHz
    Graphics Card(s)
    Intel HD 630 Graphics onboard
    Sound Card
    Realtek HD Audio
    Monitor(s) Displays
    LG E2442
    Screen Resolution
    1920x1080
    Hard Drives
    1 x Samsung 970 EVO PLUS 500GB NVMe SSD, 1 x WD_BLACK SN770
    250GB NVMe SSD (OS and programs), 1 x WD_BLACK SN770
    500GB NVMe SSD (Data)
    Case
    Lenovo SFF
    Keyboard
    Cherry Stream TKL JK-8600US-2 Wired
    Mouse
    LogiTech M510 wireless
    Internet Speed
    Fast (for fixed wireless!)
    Browser
    Chrome, sometimes Firefox
    Antivirus
    Malwarebytes Premium & Defender (working together beautifully!)
  • At a glance

    11 Pro 24H2 26100.2454i5-8400 @ 2.80GHz32GB DDR4 @ 2600MHzIntel HD 630 Graphics onboard
    Operating System
    11 Pro 24H2 26100.2454
    Computer type
    PC/Desktop
    Manufacturer/Model
    Lenovo ThinkCentre M920S SFF
    CPU
    i5-8400 @ 2.80GHz
    Motherboard
    Lenovo 3132
    Memory
    32GB DDR4 @ 2600MHz
    Graphics card(s)
    Intel HD 630 Graphics onboard
    Sound Card
    Realtek High Definition Audio onboard
    Monitor(s) Displays
    LG FULL HD (1920x1080@59Hz)
    Screen Resolution
    1920 x 1080
    Hard Drives
    1 x Samsung 970 EVO PLUS NVMe; 1 x Samsung 980 NVMe SSD
    Case
    Lenovo Think Centre SFF
    Keyboard
    Cherry Stream TKL JK-8600US-2 Wired
    Mouse
    LogiTech M510 wireless
    Internet Speed
    Fast (for fixed wireless!)
    Browser
    Chrome
    Antivirus
    Malwarebytes Premium and MS Defender, beautiful together
PowerShell can return DayofWeek as an integer.
0 = Sunday
1 = Monday
6 = Saturday

Code:
@echo off
powershell -nop "if ([int](Get-Date).DayOfWeek -le 1) { exit 1 }"

if %ERRORLEVEL% EQU 1 (
    @echo script exit
) else (
    @echo script continue
)
 

My Computer My Computer

At a glance

Windows 7
OS
Windows 7
if yesterday's date = SUNDAY OR SATURDAY.
is that the same as todays date = Monday or Sunday
 

My Computers My Computers

  • At a glance

    Win7,Win11i7-97002x16gb 3600mhz
    OS
    Win7,Win11
    Computer type
    PC/Desktop
    CPU
    i7-9700
    Motherboard
    gigabyte b365m ds3h
    Memory
    2x16gb 3600mhz
    Monitor(s) Displays
    benq gw2480
    PSU
    bequiet pure power 11 400CM
    Cooling
    cryorig m9i
  • At a glance

    win7,win11i5-84002x8gb 3200
    Operating System
    win7,win11
    Computer type
    PC/Desktop
    CPU
    i5-8400
    Motherboard
    gigabyte b365m ds3h
    Memory
    2x8gb 3200
    PSU
    xfx pro 450
True. Except a numeric value works for any international locale.
 

My Computer My Computer

At a glance

Windows 7
OS
Windows 7
Garlin,

Works great, thanks for the help.
 

My Computer My Computer

At a glance

windows 11 prointel core i7-11700f12 gb
OS
windows 11 pro
Computer type
PC/Desktop
Manufacturer/Model
dell
CPU
intel core i7-11700f
Memory
12 gb
Monitor(s) Displays
3
Hard Drives
256
Keyboard
wireless
Mouse
wireless
Internet Speed
50 mb
This would be a batch way to do it, but I'm a PowerShell person myself.
Batch:
for /f %%a in ('date /t') do (
if "%%a" NEQ "Mon" (
  if "%%a" NEQ "Sat" (
    echo do something here
  )
)
)
 

My Computer My Computer

At a glance

Windows 11 Pro 25H212th Gen Core i7-1260P64 GB Micron PC4-25600Intel Iris Xe Graphics
OS
Windows 11 Pro 25H2
Computer type
PC/Desktop
Manufacturer/Model
Intel NUC12WSHi7
CPU
12th Gen Core i7-1260P
Motherboard
NUC12WSBi7
Memory
64 GB Micron PC4-25600
Graphics Card(s)
Intel Iris Xe Graphics
Sound Card
on-board Realtek HD Audio
Monitor(s) Displays
Dell U3219Q
Screen Resolution
3840 x 2160
Hard Drives
Samsung SSD 990 PRO 1TB
Crucial MX500 2 TB
Antivirus
Microsoft Defender

Latest Support Threads

Back
Top Bottom