From the computer of: dtech10
(1 recipe)
Created: Nov 21, 2005
Hi
This will calculate the date in +- days time.
There one for dd/mm/yyyy and one for mm/dd/yyyy date formats.
Usage: ThisBatchFile.bat dd/mm/yyyy +-No. Days
ie ThisBatchFile.bat 20/11/2005 -21
The Date in 21 days ago.
English Date Format dd/mm/yyyy
======================================
@echo off
rem Calculating Dates dd/mm/yyyy Format
setlocal
echo %1 > ~Date.txt
set WDays=WedThuFriSatSunMonTue
for /f "tokens=1-4 delims=/ " %%a in (~Date.txt) do (
set dd=%%a
set mm=%%b
set yy=%%c
)
if %dd% LSS 10 set dd=%dd:~1%
if %mm% LSS 10 set mm=%mm:~1%
set mo=%mm%
set yr=%yy%
if %mm% LSS 3 (
set /a mo=%mo%+12
set /a yr=%yr%-1
)
set /a mo=%mo%+1
set /a a=%yr%/100
set /a b=2-%a%+%a%/4
set /a jd=%yr%*36525/100+%mo%*306001/10000+%dd%+%b%-694084
if %dd% LSS 10 set dd=0%dd%
if %mm% LSS 10 set mm=0%mm%
set /a Pos=(%jd%%%7)*3
set WDay=!WDays:~%Pos%,3!
set /a jd=%jd%+%2
set /a yy=%jd%*100/36525
set /a dd=%jd%-%yy%*36525/100
set /a mm=%dd%*10/306
set /a dd=%dd%-(%mm%*306+5)/10
if %dd%==0 (
set dd=31
set /a mm=%mm%-1
if %mm%==0 set dd=29
)
set /a mm=%mm%+3
if %mm% GTR 12 (
set /a mm=%mm%-12
set /a yy=%yy%+1
)
set /a yy=%yy%+1900
if %dd% LSS 10 set dd=0%dd%
if %mm% LSS 10 set mm=0%mm%
echo Today=%WDay% %1
set /a Pos=(%jd%%%7)*3
set WDay=!WDays:~%Pos%,3!
set CDate=%WDay% %dd%/%mm%/%yy%
echo NDate=%CDate%
del ~Date.txt
setlocal
==============================
American Date Format mm/dd/yyyy
==============================
@echo off
rem Calculating Dates mm/dd/yyyy Format
setlocal
echo %1 > ~Date.txt
set WDays=WedThuFriSatSunMonTue
for /f "tokens=1-4 delims=/ " %%a in (~Date.txt) do (
set mm=%%a
set dd=%%b
set yy=%%c
)
if %dd% LSS 10 set dd=%dd:~1%
if %mm% LSS 10 set mm=%mm:~1%
set mo=%mm%
set yr=%yy%
if %mm% LSS 3 (
set /a mo=%mo%+12
set /a yr=%yr%-1
)
set /a mo=%mo%+1
set /a a=%yr%/100
set /a b=2-%a%+%a%/4
set /a jd=%yr%*36525/100+%mo%*306001/10000+%dd%+%b%-694084
if %dd% LSS 10 set dd=0%dd%
if %mm% LSS 10 set mm=0%mm%
set /a Pos=(%jd%%%7)*3
set WDay=!WDays:~%Pos%,3!
set /a jd=%jd%+%2
set /a yy=%jd%*100/36525
set /a dd=%jd%-%yy%*36525/100
set /a mm=%dd%*10/306
set /a dd=%dd%-(%mm%*306+5)/10
if %dd%==0 (
set dd=31
set /a mm=%mm%-1
if %mm%==0 set dd=29
)
set /a mm=%mm%+3
if %mm% GTR 12 (
set /a mm=%mm%-12
set /a yy=%yy%+1
)
set /a yy=%yy%+1900
if %dd% LSS 10 set dd=0%dd%
if %mm% LSS 10 set mm=0%mm%
echo Today=%WDay% %1
set /a Pos=(%jd%%%7)*3
set WDay=!WDays:~%Pos%,3!
set CDate=%WDay% %mm%/%dd%/%yy%
echo NDate=%CDate%
del ~Date.txt
Subscribe to the Tech-Recipes Newsletter
You can get tips like this delivered in your email every week!
We will never, ever sell your email address or spam you.
Related recipes:
Supressing Prompts In Batch Files While Deleting All Files
Supress Responses From Commands In Batch Files
Batch Files : Get users default printer via registry (WinXP)
XP Batch Files: Copy images from camera to pc and organize by date
Using variables in Windows batch files
XP batch files: Create variable for current user account and find current user
Batch File Converting of Video Files: SageTV example
Create Batch File to Start or End Window Services
XCOPY command : Using the /EXCLUDE flag
Windows XP/Vista: Use a Batch File for Quickly Restarting explorer.exe
Sponsored links
Login
Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.Search
Tech Recipes
· Home
· Mac OS X
· Solaris
· Windows
· Programming
· UNIX
· Cisco
· MySQL
· Google
· Instant messaging
· Add recipes
· Leave feedback
· Recommend us
· RSS Syndication
Hot recipes
XP: Small, Free Way to Use and Mount Images (ISO files) Without Burning Them
Make XP look like Windows Vista / Longhorn for free!
Vista: Should I Install 64-bit or 32-bit Version? (x64 vs x86)
Hacks to Beat Rapidshare Download Limits and Waiting Time
How Do I Use or Open Bin, Cue, or ISO Files?
SMS through E-Mail: Cingular, Nextel, Sprint, T-Mobile, Verizon, Virgin Mobile
MySpace Hack: View Pictures and Comments on a Private Profile
MySpace: Hack to Dowload Any Song on Myspace
Who's Online
There are currently, 1951 guest(s) and 1 member(s) that are online.
You are Anonymous user. You can register for free by clicking here
Information
Wish to advertise with us?
All logos and trademarks in this site are property of their respective owner. The comments and forum posts are property of their posters, all the rest © 2003-2007 by QD Ideas, LLC.
Users of this site are legally bound by the Terms and conditions and Disclaimer. Do not use this web site if you do not agree with these policies.
The members, admins, and authors of this website respect your privacy.
Page Generation: 0.71 Seconds
Sun Sep 7 18:03:02 2008