Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8527593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:36:02+00:00 2026-06-11T08:36:02+00:00

I have a script that does a simple XCOPY routine for backing up all

  • 0

I have a script that does a simple XCOPY routine for backing up all our corporate files:

@echo off
IF %time:~0,2% GTR 7 (
    IF %time:~0,2% LSS 21 (

    XCOPY "R:\Sage Src" "S:\lastdata" /D /Y /E /R /K /C /H /I >> S:\sageBackupLog-%date:~-4,4%-%date:~-7,2%-%date:~-10,2%-hour%time:~0,2%.txt

    XCOPY "R:\importantStuff" "V:\lastdata" /D /Y /E /R /K /C /H /I 
    EXIT /B 0
    )
)

But ever since wrapping it all in the two IF statements, it no longer outputs the hour.

I have tried set %hour%=%time:~0,2% but it doesn’t work, returning an invalid parameters error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:36:03+00:00Added an answer on June 11, 2026 at 8:36 am

    There are two main problems here.

    First of all, change your set command into this: set hour=%time:~0,2% (hour without enclosing %-signs)

    Next thing is, that times with a single digit hour value like 9:00 o’clock will be printed like:

    " 9:00:00.00"
    

    with a leading space in front of the first digit. This is the reason for your error message, as your file name might resolve to something like:

    sageBackupLog-2012-09-11-hour 9.txt
    

    This actually forms two parameters as the name is not enclosed with "

    To overcome this and print a leading zero for these times, you can use a second set statement doing a string replacement, changing spaces to zeros:

    set hour=%time:~0,2%
    set hour=%hour: =0%
    

    You can then safely use %hour% instead of %time:~0,2% in your script.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fairly simple bash script that does some grep to find all
I have a simple script that does some search and replace. This is basically
I have a ColdFusion script that does: <cfset content = replace(content,&##147;,,all)> Which replaces &147;
i have a script that does a lot of processing on some rows from
Currently we have a script that does maven build + tomcat deploy. Deploying to
So, I have GreaseMonkey Script that does some operations with integers and then sets
I have a bash script that does ssh to a remote machine and executes
I have a PHP script that does the following: Uses file_get_contents() to get content
I have a ruby script that does a few perforce operations (through the scripting
I have a PHP script that does basic encryption of a string through the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.