Solved . yesterday's date in dos


junieman

New member
Local time
9:28 PM
Posts
20
OS
windows 11 pro
I have a bat file and I am trying to get yesterday's date in it.
See attached for the code and the error message.
It shows the error at the end of the file.
 
Windows Build/Version
Windows 11 Version 2H2 (OS BUILD 22000.795)

Attachments

  • BAT FILE SCRIPT.txt
    1.8 KB · Views: 1

My Computer

System One

  • 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

Bree

Well-known member
Guru
VIP
Local time
2:28 AM
Posts
6,364
Location
S/E England, UK
OS
Windows 11 Home
Sorry, I cannot get your script to produce any errors. Works correctly for me, regardless of whether I set my regional format to English (United Kingdom) or English (United States).

1657990528102.png
 

My Computers

System One System Two

  • OS
    Windows 11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Acer Aspire 3 A315-23
    CPU
    AMD Athlon Silver 3050U
    Memory
    8GB
    Graphics Card(s)
    Radeon Graphics
    Monitor(s) Displays
    laptop screen
    Screen Resolution
    1366x768 native resolution, up to 2560x1440 with Radeon Virtual Super Resolution
    Hard Drives
    1TB Samsung EVO 870 SSD
    Browser
    Edge, Firefox
    Antivirus
    Defender
    Other Info
    fully 'Windows 11 ready' laptop. Windows 10 C: partition migrated from my old unsupported 'main machine' then upgraded to 11. A test migration ran Insider builds for 2 months. When 11 was released on 5th October it was re-imaged back to 10 and was offered the upgrade in Windows Update on 20th October. Windows Update offered the 22H2 Feature Update on 20th September 2022.

    My SYSTEM THREE is a Dell Latitude 5410, i7-10610U, 32GB RAM, 512GB ssd, Windows 11 Pro.

    My SYSTEM FOUR is a 2-in-1 convertible Lenovo Yoga 11e 20DA, Celeron N2930, 4GB RAM, 128GB ssd. Unsupported device: currently running Win10 Pro, plus Win11 Pro 22H2 RTM as a native boot vhdx.
  • Operating System
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    Dell Lattitude E4310
    CPU
    i5 M 520
    Motherboard
    0T6M8G
    Memory
    4GB
    Screen Resolution
    1366x768
    Hard Drives
    500GB HDD
    Browser
    Firefox, Edge
    Antivirus
    Defender
    Other Info
    unsupported machine: Legacy bios, MBR, TPM 1.2, upgraded from W10 to W11 using W10/W11 hybrid install media workaround. In-place upgrade to 22H2 using ISO and a workaround.

    My SYSTEM THREE is a Dell Latitude 5410, i7-10610U, 32GB RAM, 512GB ssd, Windows 11 Pro.

    My SYSTEM FOUR is a 2-in-1 convertible Lenovo Yoga 11e 20DA, Celeron N2930, 4GB RAM, 128GB ssd. Unsupported device: currently running Win10 Pro, plus Win11 Pro 22H2 RTM as a native boot vhdx.

neemobeer

Member
Member
Local time
7:28 PM
Posts
53
OS
Windows 11
Seems like this would be a lot easier with Powershell.
Powershell:
(Get-Date).AddDays(-1).ToString("yyyyMMdd")
 

My Computer

System One

  • OS
    Windows 11

junieman

New member
Thread Starter
Local time
9:28 PM
Posts
20
OS
windows 11 pro
I tried Powershell and got the same results.
I had to add the path C:\Windows\System32 before C:\Windows\System32\cscript and the error went away.
Thanks for the help
 

My Computer

System One

  • 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

Try3

Well-known member
Power User
VIP
Local time
2:28 AM
Posts
840
Location
The proper part of London
OS
Windows 11 Home x64 Version 21H2 Build 22000.978
It seems to me that your Path does not include C:\Windows\System32, which is a default entry.

In a command prompt, enter the command
Path
to see what is set in yours.

Check the syntax to see how to add a folder to your path by using the command
Path /?
As you'll see the answer is
Path %Path%;C:\Windows\System32

All the best,
Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 21H2 Build 22000.978
Top Bottom