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 8132029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:14:43+00:00 2026-06-06T09:14:43+00:00

I would like to set the date in a Windows batch file to 7

  • 0

I would like to set the date in a Windows batch file to 7 days ago from today. I would like to do this in the following format.

set today=%date:~10,4%-%date:~4,2%-%date:~-7,2%

Any ideas how to subract the 7 day time delta here ?

  • 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-06T09:14:46+00:00Added an answer on June 6, 2026 at 9:14 am

    I posted the description below in some site some time ago:


    The following Batch files convert from Date to Julian Day Number an viceversa:

    DATETOJULIAN.BAT:

    @ECHO OFF
    REM CONVERT DATE TO JULIAN DAY NUMBER
    REM ANTONIO PEREZ AYALA
    REM GET MONTH, DAY, YEAR VALUES
    FOR /F "TOKENS=1-3 DELIMS=/" %%A IN ("%1") DO SET MM=%%A& SET DD=%%B& SET YY=%%C
    REM ELIMINATE LEFT ZEROS
    SET /A DD=10%DD% %% 100, MM=10%MM% %% 100
    REM CALCULATE JULIAN DAY NUMBER
    IF %MM% LSS 3 SET /A MM+=12, YY-=1
    SET /A A=YY/100, B=A/4, C=2-A+B, E=36525*(YY+4716)/100, F=306*(MM+1)/10, JDN=C+DD+E+F-1524
    

    JULIANTODATE.BAT:

    REM CONVERT JULIAN DAY NUMBER TO MONTH, DAY, YEAR
    REM ANTONIO PEREZ AYALA
    SET /A W=(%1*100-186721625)/3652425, X=W/4, A=%1+1+W-X, B=A+1524, C=(B*100-12210)/36525, D=36525*C/100, E=(B-D)*10000/306001, F=306001*E/10000, DD=B-D-F, MM=E-1, YY=C-4716
    IF %MM% GTR 12 SET /A MM-=12, YY+=1
    REM INSERT LEFT ZEROS, IF NEEDED
    IF %DD% LSS 10 SET DD=0%DD%
    IF %MM% LSS 10 SET MM=0%MM%
    REM SHOW THE DATE
    ECHO %MM%/%DD%/%YY%
    

    This way, to add/subtract a number of days to a date use the following lines:

    CALL DATETOJULIAN %DATE%
    SET /A NEWDATE=JDN+DAYS
    CALL JULIANTODATE %NEWDATE%
    

    Regards…

    Reference: http://quasar.as.utexas.edu/BillInfo/JulianDatesG.html


    You just need to adjust your date format if it is not MM/DD/YYYY.

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

Sidebar

Related Questions

i would like to set the date format of all the dates in my
I would like to set today's date as a maxdate for jQuery datepicker in
I would like to set some values in context.xml file and access the same
I would like to set a background image for the entire application for Windows
I would like set a default value for a date picker field in a
This is driving me nuts so any advice from fellow users would be welcome.
I would like to set the date time of some VM servers to be
I would like to set the log file name for a log4j and log4net
I have a set of date strings in the following format: $date = 'month_name
I used the same command syntax above as in Mysql and would like set

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.