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

DOS Time in h:mm:ss vs hh:mm:ss

4,329 views
Skip to first unread message

Gary Segal

unread,
Feb 16, 2011, 11:51:22 AM2/16/11
to
Hi,
I need some help with time format.
I need to get time in hh:mm:ss format, but my ,bat file gets it in
h:mm:ss

I already changed control panel (Region and Language) to be hh:mm:ss
tt still get it in the time in h:mm:ss. I ran it on my other machine
and get the same results.

Does anyone have an Idea how to take care of it?
Thanks.

here is my code.

ren Y:\XML\NEO.xml N%time:~0,2%%time:~3,2%%time:~6,3%xml
ren Y:\XML\LOG.txt L%time:~0,2%%time:~3,2%%time:~6,3%txt

also is there a way to use a variable to use it with Ren and/or Move
commands.
for example:

set XName = N%time:~0,2%%time:~3,2%%time:~6,3%xml
set LName = L%time:~0,2%%time:~3,2%%time:~6,3%txt

ren NEO.xml XName
move XName Y:\XML\%FolderName%

What is the right syntax

Thank you
Gary

Tim Meddick

unread,
Feb 16, 2011, 1:40:02 PM2/16/11
to

I cannot speck for your batch-file re-naming thing... however, I will
comment on the discrepancy between Windows Regional Options control panel
and the date / time as displayed in a Windows Command Prompt (cmd.exe).

Though changing the settings in Regional Settings control panel to :

DATE = 16-02-11 (dd-MM-yy) (separator - )
TIME = 6:35pm (h:mm tt) (separator : )

...will result in the Command Prompt displaying :

Echo {%DATE%} > 16-02-11
Echo {%TIME%} > 18:35:29.57


...so we see that the DATE configuration in the Regional Settings control
panel have complete control over the output of the special DATE variable -
but NOT over the special TIME environment variable - we see no matter how
the control panel is set the output remains the same (that is; to include
hundredths of seconds ).

But where BOTH DO make a difference, is in the (cmd.exe) Command Prompt
"date & time" command's output, thus ;

date/t > 16-02-11

time/t > 06.35pm

...and you WILL see any changes made to both DATE and TIME in Regional
Settings control panel reflected in the output of either command (date/t or
time/t).

==

Cheers, Tim Meddick, Peckham, London. :-)


"Gary Segal" <sega...@gmail.com> wrote in message
news:064fd01e-0f84-4b58...@f36g2000pri.googlegroups.com...

Gary Segal

unread,
Feb 16, 2011, 2:20:36 PM2/16/11
to
On Feb 16, 1:40 pm, "Tim Meddick" <timmedd...@o2.co.uk> wrote:
> I cannot speck for your batch-file re-naming thing... however, I will
> comment on the discrepancy between Windows Regional Options control panel
> and the date / time as displayed in a Windows Command Prompt (cmd.exe).
>
> Though changing the settings in Regional Settings control panel to :
>
> DATE    =   16-02-11 (dd-MM-yy) (separator - )
> TIME    =    6:35pm    (h:mm tt)    (separator : )
>
> ...will result in the Command Prompt displaying :
>
> Echo {%DATE%}    >    16-02-11
> Echo {%TIME%}     >    18:35:29.57
>
> ...so we see that the DATE configuration in the Regional Settings control
> panel have complete control over the output of the special DATE variable -
> but NOT over the special TIME environment variable - we see no matter how
> the control panel is set the output remains the same (that is; to include
> hundredths of seconds ).
>
> But where BOTH DO make a difference, is in the (cmd.exe) Command Prompt
> "date & time" command's output, thus ;
>
> date/t   >  16-02-11
>
> time/t   >   06.35pm
>
> ...and you WILL see any changes made to both DATE and TIME in Regional
> Settings control panel reflected in the output of either command (date/t or
> time/t).
>
> ==
>
> Cheers,    Tim Meddick,    Peckham, London.    :-)
>
> "Gary Segal" <segalg...@gmail.com> wrote in message

>
> news:064fd01e-0f84-4b58...@f36g2000pri.googlegroups.com...
>
>
>
> > Hi,
> > I need some help with time format.
> > I need to get time in hh:mm:ss format, but my ,bat file gets it in
> > h:mm:ss
>
> > I already changed control panel (Region and Language) to be hh:mm:ss
> > tt still get it in the time in h:mm:ss. I ran it on my other machine
> > and get the same results.
>
> > Does anyone have an Idea how to take care of it?
> > Thanks.
>
> > here is my code.
>
> > ren Y:\XML\NEO.xml N%time:~0,2%%time:~3,2%%time:~6,3%xml
> > ren Y:\XML\LOG.txt L%time:~0,2%%time:~3,2%%time:~6,3%txt
>
> > also is there a way to use a variable to use it with Ren and/or Move
> > commands.
> > for example:
>
> > set XName = N%time:~0,2%%time:~3,2%%time:~6,3%xml
> > set LName = L%time:~0,2%%time:~3,2%%time:~6,3%txt
>
> > ren  NEO.xml XName
> > move  XName Y:\XML\%FolderName%
>
> > What is the right syntax
>
> > Thank you
> > Gary- Hide quoted text -
>
> - Show quoted text -

Thanks
Here is how to take care of the time in h:mm:ss format

Set FolderName=%date:~10,4%%date:~4,2%%date:~7,2%
Set Time=%time: =0%
Set Time=%time::=%
Set Time=%time:~0,6% REM<---- gives you date in 083752(08:37:52)

IF EXIST Y:\XML\NEO.XML ECHO File Found!

IF EXIST Y:\XML\LOG.TXT ECHO File Found!

Set XName = N%time%.XML
Set LName = L%time%.TXT

ren NEO.XML %XName%
ren LOG.TXT %LName%

Tim Meddick

unread,
Feb 16, 2011, 5:00:48 PM2/16/11
to
Tried out your supplied script...........

Batch-file output :

File Found
File Found
The syntax of the command is incorrect.
The syntax of the command is incorrect.


P.S. I absolutely copied / pasted the script into the contents of a
batch-file and ran it. - It was the same as what you posted.

==

Cheers, Tim Meddick, Peckham, London. :-)

"Gary Segal" <sega...@gmail.com> wrote in message

news:2fc9a76e-8fb7-4e57...@a28g2000prb.googlegroups.com...

Todd Vargo

unread,
Feb 16, 2011, 11:48:28 PM2/16/11
to
<reformated to proper quoting standards>

Tim Meddick wrote:


>> "Gary Segal" <sega...@gmail.com> wrote:
>>
>> Thanks
>> Here is how to take care of the time in h:mm:ss format
>>
>> Set FolderName=%date:~10,4%%date:~4,2%%date:~7,2%
>> Set Time=%time: =0%
>> Set Time=%time::=%
>> Set Time=%time:~0,6% REM<---- gives you date in 083752(08:37:52)
>>
>> IF EXIST Y:\XML\NEO.XML ECHO File Found!
>>
>> IF EXIST Y:\XML\LOG.TXT ECHO File Found!
>>
>> Set XName = N%time%.XML
>> Set LName = L%time%.TXT
>>
>> ren NEO.XML %XName%
>> ren LOG.TXT %LName%

> Tried out your supplied script...........


>
> Batch-file output :
>
> File Found
> File Found
> The syntax of the command is incorrect.
> The syntax of the command is incorrect.
>
>
> P.S. I absolutely copied / pasted the script into the contents of a
> batch-file and ran it. - It was the same as what you posted.

After the past week's discussions of not using the intrinsic variable names
of DATE or TIME as user variable names and spaces around equal signs, we
seem to still be gluttons for punishment.

The messages above are easily explained.

1. The files NEO.XML and LOG.TXT appear to exist in Y:\XML\ however, the
REName commands failed to include the Y:\XML\ path in the REN source name.
Thus, it assumes the files exist in the current folder.

2. Variables "XName " and "LName " are being set with spaces on both sides
of the equal sign. Hence the names being set include the trailing space but
%XName% and %LName% do not include the trailing spaces. Likewise, the values
being set to
N%time%.XML and L%time%.TXT both include a preceding space (however, in this
case are not causing a problem).

The following is how I would rewrite the code. (YMMV)

@echo off
SET "mydate=%date%"
Set "FolderName=%mydate:~10,4%%mydate:~4,2%%mydate:~7,2%"
IF NOT exist Y:\XML\%FolderName% MD Y:\XML\%FolderName%

Set "mytime=%time: =0%"
Set "mytime=%mytime::=%"
Set "mytime=%mytime:~0,6%"
REM<---- sets mytime as hhmmss 083752(08:37:52)

IF EXIST Y:\XML\NEO.XML (
ECHO Moving Y:\XML\NEO.XML to Y:\XML\%FolderName%\N%mytime%.XML
MOVE Y:\XML\NEO.XML Y:\XML\%FolderName%\N%mytime%.XML
)

IF EXIST Y:\XML\LOG.TXT (
ECHO Moving Y:\XML\LOG.TXT to Y:\XML\%FolderName%\L%mytime%.TXT
MOVE Y:\XML\LOG.TXT Y:\XML\%FolderName%\L%mytime%.TXT
)


--
Todd Vargo

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

Tim Meddick

unread,
Feb 18, 2011, 8:42:01 AM2/18/11
to
I actually did get that before I posted....

The main reason for posting, anyway, that the code had failed, was to bring
that fact to the OP's attention...

...and I thank you for going into detail of exactly what went wrong for
him.

==

Cheers, Tim Meddick, Peckham, London. :-)


"Todd Vargo" <tlv...@sbcglobal.netz> wrote in message
news:iji9c5$uqr$1...@news.albasani.net...

foxidrive

unread,
Feb 18, 2011, 8:52:33 AM2/18/11
to
On 19/02/2011 00:42, Tim Meddick wrote:
> I actually did get that before I posted....
>
> The main reason for posting, anyway, that the code had failed, was to
> bring that fact to the OP's attention...
>
> ....and I thank you for going into detail of exactly what went wrong for
> him.

Please stop top posting. You can see that it is not normal in this group.


Remember the old adage: "When in Rome, do as the Roman's do..."


--
Regards,
Mic

Tim Meddick

unread,
Feb 18, 2011, 9:19:32 AM2/18/11
to
I think it anal in the extreme, to try and impose petty rules that do not
add nor take away from the ultimate legibility of posts or otherwise
detract or disable *anyone* from reading them.

I don't live in an "Outlook Express bubble" - I actually go to
website-interfaces to usernet groups, and view my output there from time to
time, and I can see no distinct disadvantage, whatsoever, to my
top-posting.

Far from it, I maintain that it (seem to me, at least) is allot easier to
comprehend that the answer (newer material ) comes first followed by the
older (repeated) text - included only for reference.

Only a very few people are so irritated by the practice to focus solely on
it, trying to make everyone keep to he exact-same practices as they do -
just seems very neurotic to me.

Like I said, I've looked back at my posts and find them actually much
easier to read than having to "wade" down to get to the new stuff - no idea
why anyone would think that better - but then some people do love to
blindly follow rules - and impose them!

If you have some sort of strange allergy to top-posed quotes, then please
feel free to skip over them.

Until I live in a totalitarian dictatorship of the state, where everyone is
compelled to think and act the same on pain of death, I'll be continuing do
top-post.

I hope you can get over it , see past it and just read the content - as you
are obviously able to do...

==

Cheers, Tim Meddick, Peckham, London. :-)


"foxidrive" <foxi...@gotcha.woohoo.invalid> wrote in message
news:CQu7p.65950$nZ2....@newsfe03.iad...

foxidrive

unread,
Feb 18, 2011, 9:22:46 AM2/18/11
to
On 19/02/2011 01:19, Tim Meddick wrote:
> I think it anal in the extreme

Yes, yes you are.


--
Regards,
Mic

Tim Meddick

unread,
Feb 18, 2011, 9:27:48 AM2/18/11
to
You know foxidrive, sometimes you are quite the affable fellow, and at
others.....not

==

Cheers, Tim Meddick, Peckham, London. :-)


"foxidrive" <foxi...@gotcha.woohoo.invalid> wrote in message

news:Xgv7p.12933$Vn7....@newsfe22.iad...


> On 19/02/2011 01:19, Tim Meddick wrote:
>

> < clipped >

Tim Meddick

unread,
Feb 18, 2011, 9:30:06 AM2/18/11
to
P.S. Maybe you noticed the grammatical error?

Should have read :

"You know foxidrive, at times you are quite the affable fellow, and at
others.....not"

Not..."sometimes".

foxidrive

unread,
Feb 18, 2011, 9:42:00 AM2/18/11
to
On 19/02/2011 01:19, Tim Meddick wrote:
> anal
> petty
> irritated
> neurotic

> blindly follow rules - and impose them!
> strange allergy to top-posed quotes

> Until I live in a totalitarian dictatorship of the state
> compelled to think and act the same on pain of death
> I hope you can get over it


Hmmm, and these are the mark of an affable person such as yourself?

You will note that:

1) I merely asked you to please stop top posting.

2) I pointed out that is it not the convention in the batch groups

3) illuminated the fact with an old adage, that it's nicer to follow the
norms and customs of the place you find yourself.


You replied with the ranting, as evidenced from the snippets above (not
below).


--
Regards,
Mic

Tim Meddick

unread,
Feb 18, 2011, 10:05:31 AM2/18/11
to
The remarks I made were directed at "people who do" the things I mentioned,
I never said "You were this" or "You were that".....

If you saw yourself in any of my descriptions, then it's not my fault.

In fact, the ONLY descriptive I attributed to you was to say I thought you
were "affable" (sometimes).

==

Cheers, Tim Meddick, Peckham, London. :-)


"foxidrive" <foxi...@gotcha.woohoo.invalid> wrote in message

news:Zyv7p.44326$y_7....@newsfe10.iad...

foxidrive

unread,
Feb 18, 2011, 10:40:48 AM2/18/11
to


So you can't bring yourself to follow the norms and customs of the group
you find yourself in.

Why is that?


--
Regards,
Mic

Tim Meddick

unread,
Feb 18, 2011, 1:16:35 PM2/18/11
to
"normal" is such a subjective term....

==

Cheers, Tim Meddick, Peckham, London. :-)

"foxidrive" <foxi...@gotcha.woohoo.invalid> wrote in message

news:5qw7p.44559$y_7....@newsfe10.iad...


> On 19/02/2011 02:05, Tim Meddick wrote:
>> The remarks I made were directed at "people who do" the things I
>> mentioned, I never said "You were this" or "You were that".....
>

> < clipped >

foxidrive

unread,
Feb 19, 2011, 2:15:13 AM2/19/11
to
On 19/02/2011 05:16, Tim Meddick wrote:

>> On 19/02/2011 01:19, Tim Meddick wrote:
>>> anal
>>> petty
>>> irritated
>>> neurotic
>>> blindly follow rules - and impose them!
>>> strange allergy to top-posed quotes
>>> Until I live in a totalitarian dictatorship of the state
>>> compelled to think and act the same on pain of death
>>> I hope you can get over it

>> So you can't bring yourself to follow the norms and customs of the


>> group you find yourself in.
>>
>> Why is that?
>>

*conventional quoting*

> "normal" is such a subjective term....
>
> ==
>
> Cheers, Tim Meddick, Peckham, London. :-)


And you call the ranting terms at the top of this post "normal"?


Yes, well, that's the sort of blinkered, philistine pig ignorance I've
come to expect from you non-creative garbage. You sit there on your
loathsome, spotty behinds squeezing blackheads, not caring a tinker's
cuss for the struggling artist. You excrement! You whining, hypocritical
toadies, with your colour TV sets and your Tony Jacklin golf clubs and
your bleeding Masonic secret handshakes! You wouldn't let me join, would
you, you blackballing bastards! Well, I wouldn't become a freemason now
if you went down on your lousy, stinking knees and begged me!

--
Regards,
Mic

Tim Meddick

unread,
Feb 19, 2011, 11:24:12 AM2/19/11
to

I will let your words speak for themselves on what sort of person YOU are,
and I will say no more.

foxidrive

unread,
Feb 19, 2011, 11:51:48 AM2/19/11
to
On 20/02/2011 03:24, Tim Meddick wrote:
>
> I will let your words speak for themselves on what sort of person YOU
> are, and I will say no more.

You don't like Monty Python? LOL

I expect you're not familiar with them. No matter.


--
Regards,
Mic

Esra Sdrawkcab

unread,
Feb 19, 2011, 4:26:17 PM2/19/11
to

I'm sorry, I thought this was the room for abuse.
>


--
"Nuns! NUNS! Reverse! Reverse!"

corrado...@gmail.com

unread,
Jan 29, 2014, 4:08:49 AM1/29/14
to
Set "mytime=%time: =0%"
Set "mytime=%mytime::=%"
Set "mytime=%mytime:~0,6%"

This is the right syntax: this solve my problems.
Thanks to ev'rybody.

CoCa

Stanley Daniel de Liver

unread,
Jan 29, 2014, 7:12:03 AM1/29/14
to
We waited 3 years for this answer!


--
It's a money /life balance.
0 new messages