Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.
WScript.Echo DateAdd("n",1,Now)
>>> import time,datetime>>> t = datetime.datetime.now()>>> t.ctime()'Wed Mar 31 16:30:24 2010'>>> back=datetime.datetime.fromtimestamp(time.mktime(t.timetuple())+60)>>> back.ctime()'Wed Mar 31 16:31:24 2010'
yes. as you can see python is clearly the winner here since it's four lines instead of 1.
lol. sarcasm? anyway, the datetime module in Python has much more features than what vbscript Date functions provides, if you would like to know.
datetime.datetime.fromtimestamp(time.mktime(datetime.datetime.now().timetuple())+60).ctime()
[System.DateTime]::Now.AddMinutes(1)
There is probably a faster way to do it in python, also. In fact, everything you have there could be combined (I think, just want to exercise python here):
Actually, VBScript is miles ahead of Batch but at the same time it's date support really blows, solely because it's all handled in OLEAUT32. Now, it works for your everyday date and time calculations but it leaves out important and useful things like converting between time zones and or calculating UTC times, something that from a quick look at the documentation it appears that python probably does.
That being said the date and time support in the .NET framework is "fixed" and actually works properly with UTC dates and time zone information. It's a very rich framework much like the modules included with Python. For example, in powershell, the following would display the current time plus one minute.
Can any of the codes store the new time in batch.
@echo OFFREM time format 12:46:26.94echo start time=%TIME%set HH=%TIME:~0,2%echo Hour=%HH%set MM=%TIME:~3,2%echo minutes=%MM%set /a MM1=%MM% + 1echo minutes plus 1=%MM1%
C:\batch> addminute.batstart time=17:27:13.98Hour=17minutes=27minutes plus 1=28C:\batch>
Not to be too obvious, but I think you need a plan B:What happens if the minutes value is 59?Just asking.
C:\batch> addminute.batstart time=19:59:35.10Hour=18minutes=59minutes plus 1=60C:\batch>
He's playing a game called IRL. Great graphics, *censored* gameplay.
Yes the following batch code assigns minute plus 1 to variable MM1:
Microsoft Windows XP [Version 5.1.2600](C) Copyright 1985-2001 Microsoft Corp.d:\batch>WScript.Echo DateAdd("n",1,Now)'WScript.Echo' is not recognized as an internal or external command,operable program or batch file.d:\batch>
Did I miss something?
cscript //nologo mydateadd.vbs
Not to be too obvious, but I think you need a plan B:What happens if the minutes value is 59?
@echo OFFREM time format 12:46:26.94echo start time=%TIME%set HH=%TIME:~0,2%echo Hour=%HH%set MM=%TIME:~3,2%if %MM%==59 Goto adjustecho minutes=%MM%set /a MM1=%MM% + 1echo minutes plus 1=%MM1%if %MM1%==60 goto adjustgoto end:adjustset /a MM1=0echo MM1=%MM1%Pauseset /a HH=%HH% + 1echo minutes plus 1=%MM1%echo Hour=%HH%:end
C:\batch> add2.batstart time=19:59:31.87Hour=19MM1=0Press any key to continue . . .minutes plus 1=0Hour=20C:\batch>
Code: [Select]C:\batch> add2.batstart time=20:07:14.17Hour=20minutes=07minutes plus 1=8C:\batch>
C:\batch> add2.batstart time=20:07:14.17Hour=20minutes=07minutes plus 1=8C:\batch>
how about hours? after 24 comes 00.
How about hours? after 24 comes 00.
@echo OFFREM time format 12:46:26.94echo start time=%TIME%set HH=%TIME:~0,2%echo Hour=%HH%set MM=%TIME:~3,2%if %MM%==59 Goto adjustecho minutes=%MM%set /a MM1=%MM% + 1echo minutes plus 1=%MM1%if %MM1%==60 goto adjustgoto end:adjustset /a MM1=0echo MM1=%MM1%If %HH%==23 goto endset /a HH=%HH% + 1echo minutes plus 1=%MM1%echo Hour=%HH%:endIf %HH%==23 set /a HH=0echo HH=%HH%
C:\test>test.batstart time=23:58:59.00Hour=23minutes=58minutes plus 1=59HH=0
How can I add one minute to the current time and store it as a variable
The batch solution is the best solution.
Matt123 ask for the minutes plusone minute be assigned to a "Dos" variable. This has been accomplished.
using your new code and setting TIME variable to 23:58.59.00 gives meif HH is the final answer for hours, then 0 in the above result is incorrect.
Professional administrators have done this sort of thing years ago. You can manipulate the date in batch scripts without the need to use VBscript or something like that. The trick is to understand the conversion to Julian date. The DOS DATE command does not do Julian date number, but you can convert it and do some add or subtract and come up with an answer.
@echo offecho WScript.echo(time+(1/24/60)) >> temp.vbs&&for /f "tokens=*" %%P in ('Cscript /NOLOGO temp.vbs') do set newdate=%%Pdel temp.vbs
But you need to define what a 'month' is. Often when people say 'in a month', they mean exactly 30 days.
yes. that's a vbscript statement. so you cannot run it like that. you put that in a file and then run it using cscript.exeCode: [Select]cscript //nologo mydateadd.vbs
No. There is no 24.The clock goes from 00:00 to 23:59But in 12 hour notation it goes from12:00 AM to 11:59 PMAne then from12:00 PM to 11:59 PM
No need for a script file. You can run from the command prompt:
mshta vbscript:(MsgBox(DateAdd("n",1,Now)))
No need for a script file. You can run from the command prompt:mshta vbscript:(MsgBox(DateAdd("n",1,Now)))
Microsoft Windows XP [Version 5.1.2600](C) Copyright 1985-2001 Microsoft Corp.d:\batch>WScript.Echo DateAdd("n",1,Now)
How do we save the output of mshta vbscript:(MsgBox(DateAdd("n",1,Now)))to a batch variable? Matt, the original poster, ask that the output be assigned tobatch variable.
I'm actually looking forward to the answer myself.Good luck.
for /f "delims=" %%a in ('mshta vbscript:(MsgBox(DateAdd("n",1,Now)))') do set newtime=%%aNow, I got a really strong feeling that that won't work...
I posted the mshta one-liner in response to Geek-9PM. It was merely to demonstrate how to run VBScript instructions from the command prompt."How do we save the output of mshta vbscript:(MsgBox(DateAdd("n",1,Now))) to a batch variable? I'm actually looking forward to the answer myself.
your thunder
Damper.
Matt wrote:"Greg, your batch solution worked."
Very good!Do you remember how many sides a Triangle has too?
A Triangle has four side and 360 degrees.
I certainly hope that is a attempt at humour.
A Triangle has four sides and 360 degrees.Those are facts.
How can I add one minute to the current time and store it as a variable.
@echo offrem bc4.vbs written by BC_programmerrem curDate=Nowrem WScript.echo "Current Date:" + Cstr(curDate)rem newDate = dateAdd("n",1,Now)rem WScript.echo "Date plus 1 minute" + Cstr(newdate)setlocal enabledelayedexpansionfor /f "delims=" %%i in ('cscript //nologo bc4.vbs') do (rem echo %%iset batvar="%%i"echo.echo batvar=!batvar!)
greg your batch solution worked
I assume the topic can be closed now?
p.s. : The off topic triangle information was introducted by BC_Programmer. It is difficult to remain on topic.Everyone knows the definition of triangle.