Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

changing the format of date command result

1,933 views
Skip to first unread message

happytoday

unread,
Dec 28, 2009, 4:41:19 PM12/28/09
to
I need to fix a problem with batch files that it has the command "echo
%date%" inside them . So , I run them in a lot of machines and every
machine has its own format of date .

How can I unite the format of date for all of the machines. I mean how
to make for all machines for example :
Mon 12/28/2009

or

dd/mm/yy

or

Any other format .

Thanks in advance for your help.

Gerard Bok

unread,
Dec 28, 2009, 4:50:39 PM12/28/09
to

Usually, Timo provides the answer :-)
http://www.netikka.net/tsneti/info/tscmd.htm
for a quick start.

--
met vriendelijke groet,
Gerard Bok

Larry__Weiss

unread,
Dec 28, 2009, 5:13:05 PM12/28/09
to

Timo is the best consultant for command.com and cmd.exe based solutions.
Since you crossposted to microsoft.public.windows.powershell I'll add that
I'm looking forwards to when he decides to add PowerShell to his tool box.

- Larry

Ted Davis

unread,
Dec 28, 2009, 8:31:04 PM12/28/09
to

If you use the GnuWin32 port of date (rename to gnudate.exe to avoid
conflict), then
gnudate +%m/%d/%Y
will return the date in mm/dd/yyyy format regardless of the machine's
settings. The GnuWin32 port of date and a number of other utilities are
in the CoreUtils package:
<http://gnuwin32.sourceforge.net/packages/coreutils.htm>

I find it useful to copy my c:\bin directory with it's collection of
utilities to all the machines I set up, and to carry a copy with me on
a thumb drive for other machines.

--

T.E.D. (tda...@mst.edu)

mik3

unread,
Dec 29, 2009, 4:52:12 AM12/29/09
to

you can use vbscript. See the date functions here
http://www.w3schools.com/VBscript/vbscript_ref_functions.asp

Dr J R Stockton

unread,
Dec 29, 2009, 12:20:44 PM12/29/09
to
In alt.msdos.batch message <f9a63f7a-fee7-442f-9029-72b3bd9126bf@e37g200
0yqn.googlegroups.com>, Mon, 28 Dec 2009 13:41:19, happytoday
<ehabaz...@gmail.com> posted:

@echo off
:: In Win32, use WSH/JS to set environment YYYYMMDD, using files tmp.*
echo var D = new Date() > tmp.js
echo D = (D.getFullYear()*100+D.getMonth()+1)*100+D.getDate() >> tmp.js
echo WScript.Echo( 'set YYYYMMDD='+D ) >> tmp.js
echo @echo off > tmp.bat
cscript //nologo tmp.js >> tmp.bat
del tmp.js
call tmp
del tmp.bat

From the proper ISO 8601 format YYYYMMDD, other forms are easily
derived.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk DOS 3.3 6.20 ; WinXP.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.

Todd Vargo

unread,
Dec 30, 2009, 10:55:05 AM12/30/09
to

Well done! Perhaps Timo will add this expeditious method to retrieve date in
ISO 8601 format YYYYMMDD to his repository.

On a side note: I would insert an "@" before the SET statement to eliminate
the second @echo off line and reduce the >> just > in the following line.
Also, I thought lines of .js code needed to terminate with a semi-colon, but
this works without them so I just learned something new. Thanks.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)


--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

Timo Salmi

unread,
Dec 30, 2009, 3:37:47 PM12/30/09
to
On 30.12.2009 17:55 Todd Vargo wrote:
> Dr J R Stockton wrote:
>> :: In Win32, use WSH/JS to set environment YYYYMMDD, using files tmp.*
>> echo var D = new Date() > tmp.js

>> From the proper ISO 8601 format YYYYMMDD, other forms are easily


>> derived.

> Well done! Perhaps Timo will add this expeditious method to retrieve
> date in ISO 8601 format YYYYMMDD to his repository.

Yes. Included into http://www.netikka.net/tsneti/info/tscmd001.htm

All the best, Timo

--
Prof. Timo Salmi mailto:t...@uwasa.fi ftp & http://garbo.uwasa.fi/
Hpage: http://www.uwasa.fi/laskentatoimi/english/personnel/salmitimo/
Department of Accounting and Finance, University of Vaasa, Finland
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.htm

Timo Salmi

unread,
Dec 30, 2009, 3:57:00 PM12/30/09
to
On 30.12.2009 17:55 Todd Vargo wrote:
> Well done! Perhaps Timo will add this expeditious method to retrieve date in
> ISO 8601 format YYYYMMDD to his repository.
>
> On a side note: I would insert an "@" before the SET statement to eliminate
> the second @echo off line and reduce the >> just > in the following line.

@echo off & setlocal enableextensions
> "%temp%\tmp.js" echo var D = new Date()
>> "%temp%\tmp.js" echo D =
(D.getFullYear()*100+D.getMonth()+1)*100+D.getDate()
>> "%temp%\tmp.js" echo WScript.Echo(D)
for /f %%a in ('cscript //nologo "%temp%\tmp.js"') do set YYYYMMDD=%%a
for %%f in ("%temp%\tmp.js") do if exist %%f del %%f
echo %YYYYMMDD%
endlocal & goto :EOF

Todd Vargo

unread,
Dec 30, 2009, 11:04:45 PM12/30/09
to
Timo Salmi wrote:
> On 30.12.2009 17:55 Todd Vargo wrote:
> > Well done! Perhaps Timo will add this expeditious method to retrieve
date in
> > ISO 8601 format YYYYMMDD to his repository.
> >
> > On a side note: I would insert an "@" before the SET statement to
eliminate
> > the second @echo off line and reduce the >> just > in the following
line.
>
> @echo off & setlocal enableextensions
> > "%temp%\tmp.js" echo var D = new Date()
> >> "%temp%\tmp.js" echo D =
> (D.getFullYear()*100+D.getMonth()+1)*100+D.getDate()
> >> "%temp%\tmp.js" echo WScript.Echo(D)
> for /f %%a in ('cscript //nologo "%temp%\tmp.js"') do set YYYYMMDD=%%a
> for %%f in ("%temp%\tmp.js") do if exist %%f del %%f
> echo %YYYYMMDD%
> endlocal & goto :EOF

I have always felt the leading redirection does not lend itself well to
newsgroup posting. Also, your revised code excludes Win9x/ME systems. :(

I like VBScript so here is my version. ;-)

@echo off
echo D=Now:D=Year(D)*10000+Month(D)*100+Day(D)>>"%temp%.\tmp.vbs"
echo WScript.Echo "@set YYYYMMDD=" + Cstr(D) >> "%temp%.\tmp.vbs"
cscript //nologo "%temp%.\tmp.vbs" > "%temp%.\tmp.bat"
for %%? in (cal de) do %%?l "%temp%.\tmp.bat"
del "%temp%.\tmp.vbs"
echo YYYYMMDD=%YYYYMMDD%

Timo Salmi

unread,
Dec 31, 2009, 1:58:43 AM12/31/09
to
On 31.12.2009 06:04 Todd Vargo wrote:
> Timo Salmi wrote:
>> On 30.12.2009 17:55 Todd Vargo wrote:
> I have always felt the leading redirection does not lend itself well to
> newsgroup posting. Also, your revised code excludes Win9x/ME systems. :(
>
> I like VBScript so here is my version. ;-)

Good. Whichever one uses, the essence probably is the one given by
http://msdn.microsoft.com/en-us/library/kb60e741%28VS.100%29.aspx

Message has been deleted

Todd Vargo

unread,
Dec 31, 2009, 5:50:32 PM12/31/09
to
Timo Salmi wrote:
> On 31.12.2009 06:04 Todd Vargo wrote:
> > Timo Salmi wrote:
> >> On 30.12.2009 17:55 Todd Vargo wrote:
> > I have always felt the leading redirection does not lend itself well to
> > newsgroup posting. Also, your revised code excludes Win9x/ME systems. :(
> >
> > I like VBScript so here is my version. ;-)
>
> Good. Whichever one uses, the essence probably is the one given by
> http://msdn.microsoft.com/en-us/library/kb60e741%28VS.100%29.aspx

I favor Qbasic too. ;-)
http://preview.tinyurl.com/ybarmq9

Dr J R Stockton

unread,
Dec 31, 2009, 6:31:21 PM12/31/09
to
In alt.msdos.batch message <hhftr4$clm$1...@adenine.netfront.net>, Wed, 30
Dec 2009 10:55:05, Todd Vargo <tlv...@sbcglobal.netz> posted:

>Dr J R Stockton wrote:

>> @echo off
>> :: In Win32, use WSH/JS to set environment YYYYMMDD, using files tmp.*
>> echo var D = new Date() > tmp.js
>> echo D = (D.getFullYear()*100+D.getMonth()+1)*100+D.getDate() >> tmp.js
>> echo WScript.Echo( 'set YYYYMMDD='+D ) >> tmp.js
>> echo @echo off > tmp.bat
>> cscript //nologo tmp.js >> tmp.bat
>> del tmp.js
>> call tmp
>> del tmp.bat
>>
>> From the proper ISO 8601 format YYYYMMDD, other forms are easily
>> derived.
>
>Well done! Perhaps Timo will add this expeditious method to retrieve date in
>ISO 8601 format YYYYMMDD to his repository.

It might be worth including a brief example of splitting and
reassembling, perhaps to DD.MM.YY, even though the way to do it is
indicated elsewhere in the FAQ?

>On a side note: I would insert an "@" before the SET statement to eliminate
>the second @echo off line and reduce the >> just > in the following line.
>Also, I thought lines of .js code needed to terminate with a semi-colon, but
>this works without them so I just learned something new. Thanks.

That was straight out of
<URL:http://www.merlyn.demon.co.uk/batfiles.htm>
which after test has been changed accordingly.

If a batch task needs a WSH script, then
* if the task is system-administrative, then use VBS, as the
documentation on Microsoft's Web site seems primarily aimed at VBS and
the Microsoft VBS newsgroup is more active than their JScript one;
* if the task involves Date/Time or RegExps, use JS;
* if you are a Web page author, use JS preferentially, as VBS is of
little use for the Web;
** in all cases :
(a) except sometimes,
(b) or use both.

JavaScript statements need a potentially-visible separator character; if
appropriate the system adds an internal semicolon at the end of a line
(that's not accurate, but suffices here). Many prefer to use only
actually-visible separators.

It's a pity that JavaScript was introduced for Web pages; building on
Pascal would have been much better.


FYI, all : I have a Web page which, copied among the local master of a
web site, will check local links and anchors - and also day-of-week in
yyyy-mm-dd xxx - it is linxchek.htm (read it before trying it). The
local copy can be altered to accommodate FFF dates and/or day-of-week
other than Mon-Sun.

Timo Salmi

unread,
Dec 31, 2009, 11:56:31 PM12/31/09
to
On 01.01.2010 01:31 Dr J R Stockton wrote:
> In alt.msdos.batch message <hhftr4$clm$1...@adenine.netfront.net>, Wed, 30
> Dec 2009 10:55:05, Todd Vargo <tlv...@sbcglobal.netz> posted:
>> Well done! Perhaps Timo will add this expeditious method to retrieve date in
>> ISO 8601 format YYYYMMDD to his repository.
>
> It might be worth including a brief example of splitting and
> reassembling, perhaps to DD.MM.YY, even though the way to do it is
> indicated elsewhere in the FAQ?

Perhaps that's excessive hand-holding. The same FAQ item #1 includes
several instances. Some initiative should be expected the reader.

Larry__Weiss

unread,
Jan 1, 2010, 12:21:28 AM1/1/10
to
Timo Salmi wrote:
> On 01.01.2010 01:31 Dr J R Stockton wrote:
>> In alt.msdos.batch message <hhftr4$clm$1...@adenine.netfront.net>, Wed, 30
>> Dec 2009 10:55:05, Todd Vargo <tlv...@sbcglobal.netz> posted:
>>> Well done! Perhaps Timo will add this expeditious method to retrieve
>>> date in
>>> ISO 8601 format YYYYMMDD to his repository.
>>
>> It might be worth including a brief example of splitting and
>> reassembling, perhaps to DD.MM.YY, even though the way to do it is
>> indicated elsewhere in the FAQ?
>
> Perhaps that's excessive hand-holding. The same FAQ item #1 includes
> several instances. Some initiative should be expected the reader.
>
> All the best, Timo
>

Timo, do you have any plans to learn and practice PowerShell in 2010 ?

- Larry

Timo Salmi

unread,
Jan 1, 2010, 1:01:57 AM1/1/10
to
On 01.01.2010 07:21 Larry__Weiss wrote:
> Timo, do you have any plans to learn and practice PowerShell in 2010 ?

http://groups.google.com/group/alt.msdos.batch.nt/msg/92dea92fa88a56c1
The response still holds.

Larry__Weiss

unread,
Jan 1, 2010, 1:24:06 AM1/1/10
to
Timo Salmi wrote:
> On 01.01.2010 07:21 Larry__Weiss wrote:
>> Timo, do you have any plans to learn and practice PowerShell in 2010 ?
>
> http://groups.google.com/group/alt.msdos.batch.nt/msg/92dea92fa88a56c1
> The response still holds.
>
> All the best, Timo
>

Thanks!

And, Happy New Year!

- Larry

0 new messages