Windows 10: Batch file not setting variables to DATE & TIME text valuse

Discus and support Batch file not setting variables to DATE & TIME text valuse in Windows 10 Software and Apps to solve the problem; Running the following batch script displays "downsecs = 1, DownStrtDate = and DownStrtTime =" Why are the variables DownStrtDate and DownStrtTime... Discussion in 'Windows 10 Software and Apps' started by Beach Guy, Apr 13, 2021.

  1. Beach Guy Win User

    Batch file not setting variables to DATE & TIME text valuse


    Running the following batch script displays "downsecs = 1, DownStrtDate = and DownStrtTime ="


    Why are the variables DownStrtDate and DownStrtTime not properly set to the current date and time

    SET /A downsecs = 0

    SET DownStrtDate = %DATE%
    SET DownStrtTime = %TIME%
    SET /A downsecs = %downsecs% + 1
    ECHO downsecs = %downsecs%, DownStrtDate = %DownStrtDate% and DownStrtTime = %DownStrtTime%
    PAUSE

    :)
     
    Beach Guy, Apr 13, 2021
    #1
  2. W1zzard Win User

    batch file programming-setting variables with ping replies

    Code: ( set /p foo= )<icmp_ping_log.txt[/quote] puts the first line of the text file into variable foo

    the set line can be repeated to read multiple lines into multiple variables
     
    W1zzard, Apr 13, 2021
    #2
  3. Batch file not working

    I'm afraid your batch file suffers from numerous problems. Here is a list of them:

    • I do not understand what the set YYY... is supposed to do.
    • There is no need to create variables for date, time and random. You can use them directly in your code.
    • In some countries, the %time% variable includes colons Batch file not setting variables to DATE & TIME text valuse :)). They cannot be used in file names. Same for the %date% variable if it includes forward slashes (/).
    • In batch files you MUST fully qualify all file names.
    • "Goto" statements should be avoided as much as possible. Use loops instead (see below).
    • In your copy command you MUST put double quotes around file/folder names that have embedded spaces.

    Here is a cleaned up version of your batch file:

    Code:
    @echo offset YYYYMMDD=%4%%DATE:~4,2%%DATE:~7,2%if exist C:\Output\output.txt (   copy /y C:\Output\output.txt "F:\Locker\SIC by Plawro\outputs\output%date%_%time%_%random%.txt" >nul   timeout 1 >nul)call C:\Tools\outputreinstall.bat
     
    Frederik Long, Apr 13, 2021
    #3
  4. Batch file not setting variables to DATE & TIME text valuse

    FordGT90Concept, Apr 13, 2021
    #4
Thema:

Batch file not setting variables to DATE & TIME text valuse

Loading...
  1. Batch file not setting variables to DATE & TIME text valuse - Similar Threads - Batch file setting

  2. Is it Possible to Batch Change Date & Time of File

    in Windows 10 Ask Insider
    Is it Possible to Batch Change Date & Time of File: [ATTACH] I have about 10,000 or so files that are either .mp4 or .jpg that all say they were created on the same day. I have all the timestamps in the filename in [year,month,day_hour,min,second.jpg/mp4] format. How can I transfer the date in the filename to metadata?...
  3. Batch variable-text with distance to margin output?

    in Windows 10 Network and Sharing
    Batch variable-text with distance to margin output?: Hello Together i want to set a user-defined variable that will not display the text on the far left. if you set/p n= hello writes the text is still displayed on the far left Batch variablen-text mit Abstand zum rand ausgeben?
  4. Batch variables are not output?

    in Windows 10 Network and Sharing
    Batch variables are not output?: Hello everybody I have written the following script: @echo off setlocal enableDelayedExpansion :set/p again Z=Number of rows: set/p S=Number of columns: set/a Ze=%Z%+0 set/a Sp=%S%+0 if not %Z%==%Ze% ( cls echo error.. goto again) if %Z%==0 ( echo error... goto again )...
  5. Using variables with the rename command in a batch file

    in Windows 10 Network and Sharing
    Using variables with the rename command in a batch file: Hello, I am trying to use variables in renaming a robocopy log file but I continually receive a 'syntax error'. Everything works perfectly until I use the rename command. I am using the latest build of Windows 10. Any advice will be appreciated, thank you. The batch...
  6. Batch file to current date and time

    in Windows 10 Customization
    Batch file to current date and time: Dear expert. Can you help me to batch file to change system date and time to current? Best regards, https://answers.microsoft.com/en-us/windows/forum/all/batch-file-to-current-date-and-time/2c75b187-3561-4604-b9b5-218db993a6f6
  7. date and time setting

    in Windows 10 Customization
    date and time setting: I am always having to manually change the time on my computer, the date seems to stay but the time is right for a short time and then it changes on its own. I have set the setting for manually and auto, and each setting I am having the same issue. I also noticed Eastern...
  8. Batch file paste text

    in Windows 10 Support
    Batch file paste text: Suppose I frequently want to enter "Mary had a little lamb." into a form or editor. Can this be done with a batch file? (Yes, I know about AutoHotkey.) 109978
  9. Enable Or Disable Change System Time And Date Using Batch file

    in User Accounts and Family Safety
    Enable Or Disable Change System Time And Date Using Batch file: hi, i want to disable the change time and date in windows ten using batch file, i am using this script to show and hide hidden file Code: @echo off REG ADD "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /V Hidden /T REG_DWORD /D 0 /F taskkill /f /im...
  10. Include date in file created by batch file.

    in Windows 10 Support
    Include date in file created by batch file.: How can I add to this batch command to include the date: xcopy C:\all\* Z:\Allbak\* /E /Y /C I'd like the resulting file to be named "Z:\Allbak171129" (yr mo day). The plan is to set up a task schedule to run the batch file every week. I want to keep several previous...