Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Name: Mechanix2Go
Or is the general tone of posts here getting more daffy with every passing week?
=====================================
If at first you don't succeed, you're about average.M2

OK How about date nath in NT5?
hint: change the month and date to a 'julian-like' number [0 thru 365 or 6], prepend the year, do the math and convert julian to yyyymmdd.
=====================================
If at first you don't succeed, you're about average.M2

Ok.... I think this is you trying to get free help with your homework (So I will let you figure it out alone)
Ha, M2 I have no idea where to begin. I wasn't challenging you directly... just trying to give you something to do.
What other programs do you use and how did you get so good at (your favourite name) DOS?I have learnt alot from these posts though and have created a bat file that will search a drive for files. (Sounds simple but it was learnt from scratch) I just cant figure out why you guys got so good at bat. What do you do for a living? (I am so keen to learn more but need simpler problems than the one you posted here!)
Lee

Hey Mechanix2Go, I think I got it :p I'll post when I get back from school :)
I only Batch if possible, 2000 more lines of code, oh well.

Lee, I have a hunch you have not been around these forums much, if you had you would certainly know that Mechanix2Go is in no way in need of class time, this guy knows his #*&%
Keep the old stuff running

I have ben hee long enough to know that.... and be a little cheeky!!
I take a bow when I see the name 'M2' in any post!

done...
a bit messy coding and my eye is too sleepy. 3am in the morning here.
@echo off
SetLocal EnableDelayedExpansionset /a yyyy=%date:~-4%
set /a mm=1%date:~3,2%-100
set /a dd=1%date:~0,2%-100
echo Today=%yyyy%-%mm%-%dd%Call :GetJulianDate %dd% %mm% %yyyy%
echo JulianDate=%GetJulianDate%Call :GetStdDate %GetJulianDate%
echo StandardDate=%GetStdDate%
goto:eofREM FUNCTION GetJulianDate dd as %1, month as %2, year as %3
:GetJulianDate
set /a GetJulianDate=%1
if NOT %2=='1' (
set /a loopUntil=%2-1
for /L %%i IN (!loopUntil!,-1,1) do (
call :GetNumOfDays %%i %3
set /a GetJulianDate+=!GetNumOfDays!
)
)
set GetJulianDate=%3%GetJulianDate%
set GetJulianDAte=%GetJulianDate:~2%
goto :eofREM FUNCTION GetStdDate julianDate as %1
:GetStdDate
::Julian Year 1930-2029
set jDate=%1
set /a yyyy=19%jDate:~0,2%
if !yyyy! lss 1930 set /a yyyy+=100
set /a ddd=1%jDate:~-3%-1000
for /L %%i In (1,1,12) do (
call :GetNumOfDays %%i !yyyy!
set /a ddd-=!GetNumOfDays!
if !ddd! leq 0 (
set /a mm=%%i
set /a dd=ddd+=!GetNumOfDays!
goto :breakLoop
)
)
:breakLoop
if !mm! leq 9 set mm=0!mm!
if !dd! leq 9 set dd=0!dd!
set GetStdDate=!yyyy!!mm!!dd!
goto :eof
REM FUNCTION GetNumOfDays month as %1, year as %2
:GetNumOfDays
if %1==2 (
set /a remainder=%2-%2/4*4
if !remainder!==0 (set /a GetNumOfDays=29) else (set /a GetNumOfDays=28)
) else (
for %%i in (1 3 5 7 8 10 12) do if %1==%%i set /a GetNumOfDays=31
for %%i in (4 6 9 11) do if %1==%%i set /a GetNumOfDays=30
)
goto :eoffor %%i in (10 11 12) do (if %date:~3,2%==%%i (set /a mm=%date:~3,2%) else (set /a mm=%date:~4,1%))
for /L %%i in (10,1,31) do (if %date:~0,2%==%%i (set /a dd=%date:~0,2%) else (set /a dd=%date:~1,1%))

I prefer to cheat:
Sat 12/20/2008 22.30.28.17
C:\>copy con a.bat
echo WScript.Quit DatePart("yyyy", Now) > #.vbs
cscript //NOLOGO #.vbs
set d=%ErrorLevel%
echo WScript.Quit DatePart("e: Done
y", Now) > #.vbs
cscript //NOLOGO #.vbs
set d=%d%%ErrorLevel%
del #.vbs
@echo %d%^Z
1 file(s) copied.
Sat 12/20/2008 22.33.38.22
C:\>a
Sat 12/20/2008 22.33.50.55
C:\>echo WScript.Quit DatePart("yyyy", Now) 1>#.vbs
Sat 12/20/2008 22.33.50.55
C:\>cscript //NOLOGO #.vbs
Sat 12/20/2008 22.33.50.67
C:\>set d=2008
Sat 12/20/2008 22.33.50.67
C:\>echo WScript.Quit DatePart("y", Now) 1>#.vbs
Sat 12/20/2008 22.33.50.69
C:\>cscript //NOLOGO #.vbs
Sat 12/20/2008 22.33.50.75
C:\>set d=2008355
Sat 12/20/2008 22.33.50.75
C:\>del #.vbs
2008355
Sat 12/20/2008 22.33.50.75
C:\>Edit: Other direction!
Sat 12/20/2008 22.49.42.22
C:\>copy con a.bat
echo d = WScript.Arguments(0) > #.vbs
echo d = DateSerial(Left(d, 4), 1, Right(d, Len(d) - 4)) >> #.vbs
echo WScript.Quit DatePart("yyyy", d) * 10000 + DatePart("m", d) * 100 + DatePart("d", d) >> #.vbs
cscript //NOLOGO #.vbs %1
set d=%ErrorLevel%
del #.vbs
@echo %d%^Z
1 file(s) copied.
Sat 12/20/2008 22.54.08.19
C:\>a 2008355
Sat 12/20/2008 22.54.37.94
C:\>echo d = WScript.Arguments(0) 1>#.vbs
Sat 12/20/2008 22.54.37.94
C:\>echo d = DateSerial(Left(d, 4), 1, Right(d, Len(d) - 4)) 1>>#.vbs
Sat 12/20/2008 22.54.37.94
C:\>echo WScript.Quit DatePart("yyyy", d) * 10000 + DatePart("m", d) * 100 + DatePart("d", d) 1>>#.vbs
Sat 12/20/2008 22.54.37.94
C:\>cscript //NOLOGO #.vbs 2008355
Sat 12/20/2008 22.54.38.00
C:\>set d=20081220
Sat 12/20/2008 22.54.38.00
C:\>del #.vbs
20081220
Sat 12/20/2008 22.54.38.02
C:\>

Actually, while we're screwing around, here's a fun idea. Change your TMP environment variable (either from "System Properties" or with SETX) to NUL. Log off/on, then try to download something with Firefox or Internet Explorer.
Then [don't] do it to someone else's PC.

reno,
Using DATE substring is a non-starter.
I'll read through your cade later to see what you've done withn the ,ath.
=====================================
If at first you don't succeed, you're about average.M2

i've another subroutine to get date from bios written by my guru. hehehe, i've been learning to write script from his codes the past few days at this forum.
to razor2.13:
thats a nice vbs, hope you dont mind if i use your code in my batch file.
REM FUNCTION GetDate() Return date as integer(yyyymmdd)
:GetDate
::== YMD8.bat@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 Qdebug < d.d > nul
del d.d#dat#.com
for /L %%a in (1,1,9) do if errorlevel %%a set dd=0%%a
for /L %%a in (10,1,31) do if errorlevel %%a set dd=%%a#day#.com
for /L %%a in (0,1,6) do if errorlevel %%a (for %%b in (Sun Mon Tue Wed Thu Fri Sat) do set ddd=%%b)#month#.com
for /L %%a in (1,1,9 ) do if errorlevel %%a set mm=0%%a
for %%a in ( 10 11 12) do if errorlevel %%a set mm=%%a#year#.com
if errorlevel 215 set yyyy=2007
if errorlevel 216 set yyyy=2008
if errorlevel 217 set yyyy=2009
if errorlevel 218 set yyyy=2010del #*#.com
set /a GetDate=%yyyy%%mm%%dd%
goto :eof

To be clear, that code to get date from BIOS is not mine. I think it came from dtech10.
=====================================
If at first you don't succeed, you're about average.M2

The problem with Mechanix2Go's / dtech10's method is that it's obsolete and removed from Windows 64-bit. I don't have a solution, either (excluding alternate languages).

"removed from Windows 64-bit"
huh?
=====================================
If at first you don't succeed, you're about average.M2

The wunderkind at M$ finally broke backward compatibility. LOL
=====================================
If at first you don't succeed, you're about average.M2

[Edit2]
Ok I Think I fixed the problem, sorry for re-editing but it saves the thread being unreadable. Should work with fancy date formats.
[/edit2]To get today's date in batch this seems to work in xp. Not sure about anything other systems. Probably won't work on locked down systems without access to reg.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
for /f "skip=2 tokens=3" %%a in ('reg query "HKEY_CURRENT_USER\Control Panel\International" /v sDate') do set lim=%%a
for /f "skip=4 tokens=2,*" %%a in ('reg query "HKEY_CURRENT_USER\Control Panel\International" /v sShortDate') do (
set dt=%%b
if defined lim set dt=!dt:%lim%= !
for %%c in (!dt!) do (
set /a pcnt+=1
set p!pcnt!=%%c
)
)
set dvar=%date%
if defined lim set dvar=!dvar:%lim%= !
for %%a in (%dvar%) do set nvar=%%a !nvar!
for %%a in (%nvar%) do (
call :test %%a
set /a pcnt-=1
if !pcnt!==0 goto finish
)
goto finish:test
if /i "!p%pcnt%:~0,1!"=="y" (
set tyear=%1
) else (
if /i "!p%pcnt%:~0,3!"=="mmm" (
call :month %1
) else (
if /i "!p%pcnt%!"=="dd" (
set tday=%1
) else (
if /i "!p%pcnt%!"=="d" (
set tday=%1
) else (
if /i "!p%pcnt%!"=="mm" (
set tmonth=%1
) else (
if /i "!p%pcnt%!"=="m" (
set tmonth=%1
)
)
)
)
)
)
goto :eof:month
for %%z in ("jan=1" "feb=2" "mar=3" "apr=4" "may=5" "jun=6" "jul=7" "aug=8" "sep=9" "oct=10" "nov=11" "dec=12") do set %%z
set tmonth=!%1!
goto :eof:finish
if %tyear% lss 10 set tyear=20%tyear%
if %tday% lss 10 set tday=0%tday%
if not "%tmonth:~0,1%"=="0" if %tmonth% lss 10 set tmonth=0%tmonth%
echo The day is the %tday%
echo The month is %tmonth%
echo the year is %tyear%
endlocal
pause
goto :eof

Doesn't work in w2k. But regardless, I don't see any date math. Just a way to get the layout via reg/ cp settings.
=====================================
If at first you don't succeed, you're about average.M2

True no date math, the reason I posted it was because the conversation came back to how to get a reliable source for date output from batch. I think it's worth a mention because I got a consistent output with every date setting I could think of in xp. This included dd ddd mm mmm yyyy and many other strange settings.
Sorry for interrupting your thread, I guess I'm probably the daffy one......

![]() |
![]() |
![]() |

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