Page 1 of 1

Time

Posted: Mon Jul 14, 2008 10:19 am
by venkycool
Hi all,

Can anyone let me know the windows command for current time which should show only the HOUR.

for eg: In Unix, the command is date +%H which shows the result as 11 (24 hour format) if the current time is 11:20:36.

I need the same command the get it worked in Windows.

Thanks in advance.

Posted: Mon Jul 14, 2008 10:58 am
by chulett
For an actual DOS command, all I am aware of is time /t and then you'd need to parse out the hour. If we're talking PX with the MKSToolkit then the UNIX commands can be used.

Re: Time

Posted: Mon Jul 14, 2008 11:05 am
by sachin1
echo %time:~0,2%

C:\Documents and Settings\s1>echo %time%
22:32:38.65

for above time in 24 hour format, below commad gives the output as 22

C:\Documents and Settings\sabankar>echo %time:~0,2%
22

Posted: Mon Jul 14, 2008 11:09 am
by chulett
Well, that's certainly intuitive. :P

Posted: Mon Jul 14, 2008 12:43 pm
by venkycool
Thanks alot Sachin,

I was using time /t command only. I just had a thought whether we can have only HOUR....You got it for me...

Thanks all....

Posted: Mon Jul 14, 2008 3:39 pm
by ray.wurlod
chulett wrote:Well, that's certainly intuitive. :P
That's why they're called BAT files.