| 1. |
Solve : Timer Batch.? |
|
Answer» I want to make a batch file. Sorry to disappoint you.Well, just TELL me how to store the time. If today is "March 31, 2010, 08:00:20 PM". How to store the information. Like this...... set/p "today=>" But that you have to type in manualy. set/p "today=>""March 31, 2010, 08:00:20 PM" Quote from: Geek-9pm on March 31, 2010, 07:49:24 PM Sorry to disappoint you.if he(BILL?) just wants to change the system date to 2 months earlier, there are ways to do it. GNU date provides -s option to set system date. Similarly for vbscript the SetDateTime method of win32_operatingsystem class. the cmd.exe command line date function is another way, HOWEVER, you have to figure out the maths yourself if going by pure batch. Quote from: progmer on March 31, 2010, 08:06:38 PM Well, just tell me how to store the time.Try running date /t and time /t at the command PROMPT and see what happens. Also look at %date% and %time%. Ahh-- it don't work for me! I tried to go back to February. Would it not be easier to have a calendar on the wall? Quote d:\batch>date /?Quote from: Geek-9pm on March 31, 2010, 09:03:28 PM Ahh-- it don't work for me! I tried to go back to February.ask greg the expert on date maths to help you02/31/2010 Now, why doesn't that work...hmm...better put on our thinking caps class. Quote Similarly for vbscript the SetDateTime method of win32_operatingsystem class. eww.. sometimes I forget hwo much useful crap they stripped out of VB when they created VBS. setting the date to two months prior in VB6 is as simple as: date=dateserial(year(now),Month(now)-2,day(now)) Also: yes, it work for nearly any date. For example, dateserial(1998,2,35) gave me "3/7/1998" negative numbers work, also. Anyway, dateserial() exists in VBScript, and you can use the Date command to change the date as well... or just use DateAdd(), which I complete forgot about while testing DateSerial: Code: [Select]newdate = DateAdd("m",-2,Now) Set oshell = CreateObject("WScript.Shell") oShell.run "cmd /k date " & Cstr(newdate) & "&exit" Quote from: BC_Programmer on April 01, 2010, 06:45:19 AM date=dateserial(year(now),Month(now)-2,day(now))a better variable name should be given instead of "date" since date is a valid keyword in vbscript Quote from: ghostdog74 on April 01, 2010, 07:22:00 AM a better variable name should be given instead of "date" since date is a valid keyword in vbscript Quote setting the date to two months prior in VB6 is as simple as: Assigning a date in VB6< is as simple as assigning a date-type variable to the "date" psuedo variable (which is actually a statement). As you'll notice the latter code that is actually intended for VBScript does not use the name "date" for the variable and instead opts for "newdate".Ok. Just tell me how to store the time. Store it as %abc% so when i type echo "%abc%" it will be "April 01, 2010, 09:27:31 PM" Thanks Quote from: progmer on April 01, 2010, 09:29:47 PM Ok.Look at this. Echo %date% %time% set abc=%date% %time% echo %abc% pause It will repeat the same line twice. Well Thanks For Everyone's Help. Now The Batch Should Look Like This. Code: [Select]echo off set undot=%time% set undod=%date% goto 1 :restart mshta vbscript:Execute("resizeTo 0,0:MsgBox ""System Refresh"",48,""System Refresh"":Close") :1 cls echo Welcome. Today's time is %time% %date% echo. echo You are about to change the time manualy. Please enter a time, HH-MM-SS. example: 23:59:59 set/p "sett=>" echo. echo. echo You are now going to change the date manualy. Please enter a date, MM-DD-YY. example: 12-31-2010 set/p "setd=>" echo. echo. :a echo Confirm? (Y/N) echo Time = %sett% echo Date = %setd% set/p "confirm=>" if %confirm%==Y goto change if %confirm%==y goto change if %confirm%==N goto restart if %confirm%==n goto restart mshta vbscript:Execute("resizeTo 0,0:MsgBox ""Invalid. Y or N only."",64,""Invalid"":Close") echo. echo. echo. echo. goto a :change time %sett% date %setd% :b echo Do you want to undo? (Y/N) set/p "undoing=>" if %undoing%==Y goto undo if %undoing%==y goto undo if %undoing%==N goto exit if %undoing%==n goto exit mshta vbscript:Execute("resizeTo 0,0:MsgBox ""Invalid. Y or N only."",64,""Invalid"":Close") echo. echo. goto b :undo time %undot% date %undod% mshta vbscript:Execute("resizeTo 0,0:MsgBox ""Time undo sucessfully."",64,""Undo"":Close") :c echo Do you want to restart? set/p "rstart=>" if %rstart%==Y goto restart if %rstart%==y goto restart if %rstart%==N goto exit if %rstart%==n goto exit mshta vbscript:Execute("resizeTo 0,0:MsgBox ""Invalid. Y or N only."",64,""Invalid"":Close") echo. echo. goto c :exit mshta vbscript:Execute("resizeTo 0,0:MsgBox ""You have closed the timer batch."",0,""Timer Batch"":Close") exit Good to know if there is any update for the batch. Just reply me. Quote from: progmer on March 31, 2010, 07:37:55 PM Today's time is Tue 04/06/2010 C:\batch>type timer.vbs Code: [Select]rem DateAdd(interval,number,date) rem Parameter Description rem interval Required. The interval you want to add rem Can take the following values: rem yyyy - Year rem q - Quarter rem m - Month rem y - Day of year rem d - Day rem w - Weekday rem ww - Week of year rem h - Hour rem n - Minute rem s - Second curDate=Now WScript.echo "Current Date:" + Cstr(curDate) newDate = dateAdd("m",-2,Now) WScript.echo "date - 2 Month:" + Cstr(newDate) newDate = dateAdd("m",1,Now) WScript.echo "date + 1 Month:" + Cstr(newdate) Output: C:\batch>cscript //nologo timer.vbs Current Date:4/6/2010 6:59:12 PM date - 2 Month:2/6/2010 6:59:12 PM date + 1 Month:5/6/2010 6:59:12 PM C:\batch> |
|