BATch !Time! Format

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

BATch !Time! Format

Post by VegasNath »

Set MyTime=%Time%
Set MyTime=%Mytime:~0,8%

The above will produce the time as hh:mm:ss, removing the miliseconds. How can I also remove the seconds so that I get just hh:mm?
:wales: Nathan :uk:
There's no place like home.....

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Re: BATch !Time! Format

Post by VegasNath »

I got it, the 8 represents the number of characters, so changed to 5. :)
:wales: Nathan :uk:
There's no place like home.....

User avatar
John Gray
PlatinumLounger
Posts: 5408
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: BATch !Time! Format

Post by John Gray »

You could save yourself a line with
Set MyTime=%time:~0,5%
!
But if you always want a leading zero in the hours value when it's earlier than 10:00, do
Set MyTime=%time:~0,5%
Set MyTime=%MyTime: =0%

since the time otherwise comes out at " 6:13" and not "06:13" (for example).

There are a number of other ways of achieving this, but this is the most straightforward.

LATER, for the benefit of pedants the world over...
Actually, the %time% variable has the final field value in centiseconds, not milliseconds! As in "12:34:56.78"
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15611
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: BATch !Time! Format

Post by ChrisGreaves »

VegasNath wrote:Set MyTime=%Mytime:~0,8%
I played around with date and Time formats in the attached ZIP file for a Friend.
Date was the most troublesome as users can set different date formats on their machines.
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle

User avatar
John Gray
PlatinumLounger
Posts: 5408
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: BATch !Time! Format

Post by John Gray »

That's what the :datetime subroutine previously published was supposed to do for all regional settings - apparently except Italy!
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Re: BATch !Time! Format

Post by VegasNath »

:cheers:
:wales: Nathan :uk:
There's no place like home.....

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15611
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: BATch !Time! Format

Post by ChrisGreaves »

John Gray wrote:That's what the :datetime subroutine previously published ...
Ahah! I missed this post That the one?
There's nothing heavier than an empty water bottle