Current date/time in a variable (solved)

Microsoft Windows 98 se (full product)
June 24, 2010 at 05:07:36
Specs: Windows 9x/2k/XP/Vista/7
This is solving for place current date or time to environment variable. It works under all windows versions.
One (but important) restriction - you need additional util for this operation.
This util is for UNIX, portabled to Windows. You can download it here:
This util presented in archive, subfolder usr\local\wbin
TR is util that translate, squeeze, and/or delete characters from standard input, writing to standard output.

@echo off
rem *********************************************************************
rem ******************BEGIN OF FILE**************************************
rem *********************************************************************
rem ** This file sets the current date to environment variable
rem ** this works under windows 95/98/Me/2000/XP/Vista/7/...
rem ** small example of using this batch file:
rem ** call get_date.bat
rem ** echo %date%
rem **
rem ** this file creates many small dat files in temp directory
rem ** path to temp directory should be in %TEMP% variable
rem ** be careful: this path should NOT contain spaces!
rem **
rem ** if you want to make similar action for current time,
rem ** just replace in this file the string:
rem ** date
rem ** to the string:
rem ** time
rem **
rem ** (c) Mikhed Alexander
rem *********************************************************************

echo.> %temp%\empty.dat
echo set date=>%temp%\set_date.dat

date < %temp%\empty.dat > %temp%\currdate.dat

tr.exe -d A-z\200-\377:,()[:blank:][:cntrl:]\55< %temp%\currdate.dat > %temp%\date.dat
copy %temp%\set_date.dat + %temp%\date.dat %temp%\set_date.bat > nul
tr -d \r\n < %temp%\set_date.bat > %temp%\set_date1.bat
call %temp%\set_date1.bat

rem echo current date is: %date%

del %temp%\set_date1.bat
del %temp%\set_date.bat
del %temp%\set_date.dat
del %temp%\empty.dat
del %temp%\currdate.dat
del %temp%\date.dat

rem ****************END OF FILE******************************************
rem *********************************************************************

See More: Current date/time in a variable (solved)

Report •

June 24, 2010 at 13:42:47
Why so complicated?

TIMESTMP +m.d.j | PIPESET date

would do the same job in a much more elegant way.

Admittedly you need additionals utilities for this version as well, but they can be downloaded easily from here and you gain the ability to freely define the format of the date/time string to (almost) anything you like.

The archive DOSUTILS.ZIP will contain all the utilities you need plus some more ones, even another incarnation of "TR". The file DOSUTILS.TXT which is also contained in the archive tells you the details.

Report •

July 1, 2010 at 07:23:47
No need for externals:


@echo off

echo set currdate=%%5>> the.bat
echo.|date> my.bat

Helping others achieve escape felicity


Report •

July 5, 2010 at 14:02:18
Are you actually writing about genuine (MS-)DOS?

If so, what is the command "echo.ldate" supposed to do?

Report •
Related Solutions

Ask Question