Computing.Net > Forums > Programming > Getting Win/MsDos Date Variables

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Getting Win/MsDos Date Variables

Reply to Message Icon

Name: dtech10
Date: February 24, 2007 at 13:46:31 Pacific
OS: Win XP Pro
CPU/Ram: PIII 1Gb/1Gb
Comment:

Hi
Paste each of these routines into a text file
and then run Batch File 1 to create the Com
files Weekday, Day, Month, Year.
Put these in a directory thats in your Path.
Then run Batch File 2 for Windows or Batch File 3
for both, Windows or MSDOS.
The text files and Batch File 1 can then be
deleted if required.
Running Batch File 2 or 3 on startup will
store the variables Weekday, Day, Month & Year
in your environment for use when required.

----
E 0100 B4 2A CD 21 B4 4C CD 21
N WEEKDAY.COM
RCX
A
W
Q

----
E 0100 B4 2A CD 21 B4 4C CD 21
N WEEKDAY.COM
RCX
A
W
Q

--------
E 0100 B4 2A CD 21 88 F0 B4 4C CD 21
N MONTH.COM
RCX
A
W
Q

--------
E 0100 B4 2A CD 21 89 C8 B4 4C CD 21
N YEAR.COM
RCX
A
W
Q

-------
rem Batch File 1
@echo off
debug < Weekday.scr
debug < Day.scr
debug < Month.scr
debug < Year.scr
Windows XP ect.
--------

rem Windows Xp
rem Batch File 2
@echo off
call weekday.com
set Weekday=%errorlevel%
call day.com
set Day=%errorlevel%
call month.com
set Month=%errorlevel%
call year.com
set /a Year=%errorlevel%+1792

echo Weekday Day Month Year
echo %Weekday% %Day% %Month% %Year%
echo Environment variables set


-------------------
rem Batch File 3
rem MSDOS (Also works in Windows)
@echo off
call weekday.com
for %%a in (0 1 2 3 4 5 6) do if errorlevel %%a set Weekday=%%a

call day.com
for %%a in (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) do if errorlevel %%a set Day=%%a

call month.com
for %%a in (1 2 3 4 5 6 7 8 9 10 11 12) do if errorlevel %%a set Month=%%a

call year.com
if errorlevel 215 set Year=2007
if errorlevel 216 set Year=2008
if errorlevel 217 set Year=2009
if errorlevel 218 set Year=2010

echo Weekday Day Month Year
echo %Weekday% %Day% %Month% %Year%
echo Environment variables set





Response Number 1
Name: Mechanix2Go
Date: February 25, 2007 at 03:26:59 Pacific
+1
Reply:

Hi dtech10,

You've got 2 weekday sections and no day part.

Weekday is 8 bytes, not a.

And you can make 'em all at once:

::== my.d
E 0100 B4 2A CD 21 B4 4C CD 21
N WEEKDAY.COM
RCX
8
W
E 0100 B4 2A CD 21 88 F0 B4 4C CD 21
N MONTH.COM
RCX
A
W
E 0100 B4 2A CD 21 89 C8 B4 4C CD 21
N YEAR.COM
RCX
A
W
Q

::==


=====================================
If at first you don't succeed, you're about average.

M2




Response Number 2
Name: dtech10
Date: February 25, 2007 at 07:54:28 Pacific
+1
Reply:

Hi Mechanix
Thanks for spotting my deliberate error.
Heres the Day One.

E 0100 B4 2A CD 21 88 D0 B4 4C CD 21
N DAY.COM
RCX
A
W
Q




Response Number 3
Name: Mechanix2Go
Date: February 26, 2007 at 03:32:46 Pacific
+1
Reply:

This should do it in one go for DOS/NT:

::==
@echo off > d.d

>> d.d echo E 0100 B4 2A CD 21 B4 4C CD 21
>> d.d echo N DAY.COM
>> d.d echo RCX
>> d.d echo 8
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 F0 B4 4C CD 21
>> d.d echo N MONTH.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 89 C8 B4 4C CD 21
>> d.d echo N YEAR.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 D0 B4 4C CD 21
>> d.d echo N DAT.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo Q

debug < d.d > nul
del d.d

dat
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set dat=0%%a
for %%a in ( 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) do if errorlevel %%a set dat=%%a
echo Date %dat%

day
if errorlevel 0 set day=Sunday
if errorlevel 1 set day=Monday
if errorlevel 2 set day=Tuesday
if errorlevel 3 set day=Wednesday
if errorlevel 4 set day=Thursday
if errorlevel 5 set day=Friday
if errorlevel 6 set day=Saturday
echo Day %day%

month
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set month=0%%a
for %%a in ( 10 11 12) do if errorlevel %%a set month=%%a
echo Month %month%

year
if errorlevel 215 set Year=2007
if errorlevel 216 set Year=2008
if errorlevel 217 set Year=2009
if errorlevel 218 set Year=2010
echo Year %Year%

del day.com
del month.com
del year.com
del dat.com
::==


=====================================
If at first you don't succeed, you're about average.

M2




Response Number 4
Name: dtech10
Date: February 26, 2007 at 16:03:56 Pacific
+1
Reply:

Hi Mechanic

Neat Job.




Reply to Message Icon

Related Posts

See More


error c2059 comparing sql datetime to...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Google Ads



Results for: Getting Win/MsDos Date Variables

Date Variable in XP Command Line FTP www.computing.net/answers/programming/date-variable-in-xp-command-line-ftp/19183.html

How to get last months date in KSH? www.computing.net/answers/programming/how-to-get-last-months-date-in-ksh/13242.html

Setting date variable in Win2000 www.computing.net/answers/programming/setting-date-variable-in-win2000/12595.html