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. Date and Time Settings

    in Windows 10 Customization
    Date and Time Settings: I would like to have my time in military time but I am unable to find a setting to change it to that. Any suggestions? https://answers.microsoft.com/en-us/windows/forum/all/date-and-time-settings/2fcabe0d-8e83-4e18-9ed4-d6e22b0b21b5
  4. 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?
  5. 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 )...
  6. 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...
  7. 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
  8. Date and time setting

    in Windows 10 Customization
    Date and time setting: Date and time /time zone setting https://answers.microsoft.com/en-us/windows/forum/all/date-and-time-setting/1e34de3e-fa5c-46f2-ad03-034d759496dd
  9. date and time set

    in Windows 10 Software and Apps
    date and time set: since updating bios date an time does not update https://answers.microsoft.com/en-us/windows/forum/apps_windows_10-winapps-appscat_productivity/date-and-time-set/e2a8ffe3-14e9-46c5-bff0-b287e3b39c07
  10. 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