Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!
Credits 4,869 Posts 1,633 Joined 2002-12-10 00:00 23-year member UID 465 Gender Male
Status Offline
Reposted from elsewhere:
----------------------
:: Parse the current date and time into multiple variables
:: Adds a zero to %hrs% if only one digit is present
@echo off
if "%1"=="GoTo:" %1%2 (Subroutine Handler)
echo @PROMPT SET TIME=$T$_SET DATE=$D$_> %TEMP%.\T1.BAT
%COMSPEC% /e:1024 /c %TEMP%.\T1.BAT > %TEMP%.\T2.BAT
type nul> %TEMP%.\T1.BAT
for %%? in (0D 10 13 27 2A) do echo e1%%?';'>> %TEMP%.\T1.BAT
for %%? in (w q) do echo %%?>> %TEMP%.\T1.BAT
DEBUG %TEMP%.\T2.BAT nul
call %TEMP%.\T2.BAT
:: Depending on the COUNTRY command from config.sys, swapping
:: the words 'month' and 'date' in next line could be necessary
call %0 GoTo: setvars %time% %date% hrs min sec dsec day month date year
FIND "= " nul
if not errorlevel=1 set hrs=0%hrs%
for %%? in (1 2) do del %TEMP%.\T%%?.BAT
echo Hrs: %hrs%
echo Min: %min%
echo Sec: %sec%
echo DSec: %dsec%
echo Day: %day%
echo Month: %month%
echo Date: %date%
echo Year: %year%
goto EOF
:setvars
if "%1"=="GoTo:" SHIFT
SHIFT
if "%9"=="" goto eof
set %9=%1
goto setvars