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

  • SEARCH
  • Home
  • 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 8075231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:55:21+00:00 2026-06-05T14:55:21+00:00

I have the following few lines in a batch file: @echo off echo Running

  • 0

I have the following few lines in a batch file:

@echo off 
echo Running dump...
"D:\wamp\bin\mysql\mysql5.5.16\bin\mysqldump" --host="localhost" --user="****" --password="****" database> "D:\wamp\backup\mysql\"back.%date:~0,2%.sql
echo Done!

Supposedly, it should create a backup file with today’s day as 01, 02, 03, …, 31, that is,

back.01.sql
back.02.sql
back.03.sql

When I run it from CMD, it actually creates it as expected, but when it is run from the scheduler it looks like:

back.Mo.sql
back.Tu.sql
back.We.sql

What date format should I use to ensure it actually created with number of the day of the month?

  • 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-05T14:55:22+00:00Added an answer on June 5, 2026 at 2:55 pm

    Working with dates and times in Windows batch is a pain.

    The most robust solution is to use WMIC to get the local date and time. It returns a value in the following format:

    YYYYMMDDhhmmss.dddddd-ttt
    
    YYYY   = year
    MM     = month
    DD     = day
    hh     = hour in 24 hour format
    mm     = minutes
    ss     = seconds
    dddddd = fractional seconds
    ttt    = time zone (minutes difference from Greenwich Mean Time)
    

    So you can use the following to get the current day of the month in a variable
    Edit – corrected starting substring location from 7 to 6

    set curDate=
    for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined curDate set curDate=%%x
    set day=%curDate:~6,2%
    

    The big advantage of this technique is it will work on any Windows machine in the world, regardless of the locale settings.


    Here is your code with the technique inserted
    Edit – corrected starting substring location from 7 to 6

    @echo off
    echo Running dump...
    set curDate=
    for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined curDate set curDate=%%x
    set "day=%curDate:~6,2%"
    "D:\wamp\bin\mysql\mysql5.5.16\bin\mysqldump" --host="localhost" --user="****" --password="****" database> "D:\wamp\backup\mysql\back.%day%.sql"
    echo Done!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the first few lines of a text file fx.txt with the following
I have a long running background process that parses a few hundred thousand lines
I have the following regular expression with which I match a few lines. Here
I have the following code in a few activities and it reads and parses
I have been following the usage of JavaScript for the past few years, and
I have the following code to create and apply a few styles for a
I have the following problem. I have a table with a few hundred thousand
I have seen the following question but I still have a few doubts. Sending
I have a few issues with the following php functions (part of a bigger
We have few components like libraries dlls When initially created I ran the following

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.