cumminbk Posted September 19, 2007 Share Posted September 19, 2007 I currently have a patch file that saves time i installed windows. right now using the %time% command i get hh.mm.ss.cc which is way more than i want. I would like the time to be save as just the hour and minutes as well if it is AM or PM. Can someone tell me what command i can add to my batch to perform this?thanks Link to comment Share on other sites More sharing options...
Yzöwl Posted September 19, 2007 Share Posted September 19, 2007 There are many different ideas for doing this, however, the answers can vary a great deal because of the way different localities display their time data and different operating system functions.A basic way based upon your current output (unknown as to whether it is in 12 or 24 hour format) is:%TIME:~0,2%:%TIME:~3,2%We would need more information in order to take this much further without over complicating matters. Link to comment Share on other sites More sharing options...
cumminbk Posted September 19, 2007 Author Share Posted September 19, 2007 (edited) thanks for the help Yzöwl. Your code gives me part of what i want. I would rather the time be 12hr clock with am or pm instead of the military time your code shows. The system time on my computer is 12hr clock with am and pm Edited September 19, 2007 by cumminbk Link to comment Share on other sites More sharing options...
Yzöwl Posted September 19, 2007 Share Posted September 19, 2007 If using XP or higher with admin privileges then for a more universal solution you could use the batch file in the attached archive.TimeIs.7z Link to comment Share on other sites More sharing options...
cumminbk Posted September 19, 2007 Author Share Posted September 19, 2007 (edited) I tried the batch file and nothing happens. The batch file just opens and sits there blank. Also i am wondering if there is a simpler method other than that batch file. Is there a command that assumes I am using a clock that is 12hr and doesnt take into effect all different time zones and performing checks for 12 hr or 24 hour clocks and so on.I liked what you posted first except i want 12hr clock and am or pm added to the time. can you produce a line of code about the same length as this? %TIME:~0,2%:%TIME:~3,2%This time is just basically a time stamp. It does not have to update itself at intervals. just grab the current system time and save it to my file oobeinfo.ini Edited September 19, 2007 by cumminbk Link to comment Share on other sites More sharing options...
Yzöwl Posted September 19, 2007 Share Posted September 19, 2007 The batch file should work as you requested. It uses WMIC and grabs the local time from your machine and puts it into the format you required.Because it uses WMIC you need to be running at least XP as an administrator. If WMIC has never ran before on your system it will take a short time to set itself up before first use. Link to comment Share on other sites More sharing options...
gunsmokingman Posted September 20, 2007 Share Posted September 20, 2007 I do not know if this is what you want. This cmd script does 1:\ Makes a VBS script that uses the time function2:\ Creates a temp SetTime.cmd that passes the VBS Time to the original cmd.Save As Time.cmd@Echo OffCLSColor F3Mode 55,5Title TimeSet VBS=%SystemDrive%\Time.vbsSet Cmd=%SystemDrive%\SetTime.cmd> %VBS% Echo Dim TS >> %VBS% Echo Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")>> %VBS% Echo Set Ts = Fso.CreateTextFile("%Cmd%")>> %VBS% Echo Ts.writeline "Set TM=" ^& Time '/-^> Varible For Time>> %VBS% Echo Ts.Close%VBS%call %Cmd%Del %VBS%Del %Cmd%Echo.Echo -^> %TM%pause Link to comment Share on other sites More sharing options...
Yzöwl Posted September 20, 2007 Share Posted September 20, 2007 Another Batch/VBS hybrid, see how this does you!@Echo off&Setlocal&Set "VBS_=%TEMP%\_$.vbs">"%VBS_%" Findstr "'VBS$" "%~f0" For /f "Delims=" %%? In ('CScript //NoLogo "%VBS_%"') Do Set T_=%%?Del %VBS_%&Echo/%T_%&Pause&GoTo :Eoftm = time() 'VBShr = hour(tm) 'VBSmn = right("0" & minute(tm),2) 'VBSSelect case true 'VBS case hr < 12 'VBS ampm = "AM" 'VBS case hr = 12 'VBS ampm = "PM" 'VBS case else 'VBS ampm = "PM" 'VBS hr = hr - 12 'VBSend Select 'VBSWScript.Echo hr & ":" & mn & " " & ampm 'VBS'VBS Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now