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?
BATch !Time! Format
-
- 5StarLounger
- Posts: 1185
- Joined: 24 Jan 2010, 12:02
- Location: Wales, UK.
BATch !Time! Format
Nathan
There's no place like home.....
There's no place like home.....
-
- 5StarLounger
- Posts: 1185
- Joined: 24 Jan 2010, 12:02
- Location: Wales, UK.
Re: BATch !Time! Format
I got it, the 8 represents the number of characters, so changed to 5. :)
Nathan
There's no place like home.....
There's no place like home.....
-
- PlatinumLounger
- Posts: 5411
- Joined: 24 Jan 2010, 08:33
- Location: A cathedral city in England
Re: BATch !Time! Format
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"
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 hospital appointment letter indicates that you won't be seeing the Consultant...
"(or one of the team)" - how your hospital appointment letter indicates that you won't be seeing the Consultant...
-
- PlutoniumLounger
- Posts: 15641
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: BATch !Time! Format
I played around with date and Time formats in the attached ZIP file for a Friend.VegasNath wrote:Set MyTime=%Mytime:~0,8%
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.
He who plants a seed, plants life.
-
- PlatinumLounger
- Posts: 5411
- Joined: 24 Jan 2010, 08:33
- Location: A cathedral city in England
Re: BATch !Time! Format
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 hospital appointment letter indicates that you won't be seeing the Consultant...
"(or one of the team)" - how your hospital appointment letter indicates that you won't be seeing the Consultant...
-
- 5StarLounger
- Posts: 1185
- Joined: 24 Jan 2010, 12:02
- Location: Wales, UK.
Re: BATch !Time! Format
Nathan
There's no place like home.....
There's no place like home.....
-
- PlutoniumLounger
- Posts: 15641
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: BATch !Time! Format
Ahah! I missed this post That the one?John Gray wrote:That's what the :datetime subroutine previously published ...
He who plants a seed, plants life.