error in date time calculations
Moderator: DosItHelp
error in date time calculations
Hello Friends
I have a big problem which I do’nt know how to bypass.
I have a long batch file which works perfect.
It makes long (hours elapsed) backup from divers selected directories, and controls the elapsed individual times and the total, according to the directories selected.
It works perfect as is to see in the first jpg image.
But some time, I think when the minutes are 8 or 0 or 9, this does not work correct and all goes to the paper – case.
Is this possible or is a mistake in my batch file ?.
By each procedure I convert the moment date and time to seconds, and after when necessary, I revert the seconds elapsed to hours, minutes and seconds. Showing, printing or recording the calcuted information
Not always but, may be 2 of 10 times.
Some cases I get the procedure as is in image 2 to see.
I’m not sure this is because the 8 or 9 ….in minute ????
The main batch takes procedures over change the date by night or changing the year. This means it can begin in a day or in a year and finish the next different one.
This a easy single example, with the translated error, but is complicated when there are more long directories to copy.
Notified error:
Number not valid. The numeric constants are decimals (17), hexadecimals (0x11) …..etc.
Is this error resolvable ?
I’m sure that I’m not the first who have this problem.
Is there any solution ?
Sorry I do'nt know how to insert the images. But if necessary I can send.
Thanks in advance for your help
Jorgegs from Spain
I have a big problem which I do’nt know how to bypass.
I have a long batch file which works perfect.
It makes long (hours elapsed) backup from divers selected directories, and controls the elapsed individual times and the total, according to the directories selected.
It works perfect as is to see in the first jpg image.
But some time, I think when the minutes are 8 or 0 or 9, this does not work correct and all goes to the paper – case.
Is this possible or is a mistake in my batch file ?.
By each procedure I convert the moment date and time to seconds, and after when necessary, I revert the seconds elapsed to hours, minutes and seconds. Showing, printing or recording the calcuted information
Not always but, may be 2 of 10 times.
Some cases I get the procedure as is in image 2 to see.
I’m not sure this is because the 8 or 9 ….in minute ????
The main batch takes procedures over change the date by night or changing the year. This means it can begin in a day or in a year and finish the next different one.
This a easy single example, with the translated error, but is complicated when there are more long directories to copy.
Notified error:
Number not valid. The numeric constants are decimals (17), hexadecimals (0x11) …..etc.
Is this error resolvable ?
I’m sure that I’m not the first who have this problem.
Is there any solution ?
Sorry I do'nt know how to insert the images. But if necessary I can send.
Thanks in advance for your help
Jorgegs from Spain
Re: error in date time calculations
No code, so i have to guess:
Numbers starting with 0 are interpreted as octal numbers, so you may use invalid numbers.
If you want to parse something like this "09:08:09" into hours minutes and seconds,
then you should avoid doing it this way (maybe hidden within a "for /F" statement):
The digits 8 and 9 are no octal numbers so this error is displayed.
You better add a 1 in front of such numbers and substract 100 from it
But you have to be careful if hours don't use leading zeroes.
penpen
Numbers starting with 0 are interpreted as octal numbers, so you may use invalid numbers.
If you want to parse something like this "09:08:09" into hours minutes and seconds,
then you should avoid doing it this way (maybe hidden within a "for /F" statement):
Code: Select all
:: for /F ... do set /A "hours=%%~a", "minutes=%%~b", "seconds=%%~c"
set /A "hours=09", "minutes=08", "seconds=09"
You better add a 1 in front of such numbers and substract 100 from it
Code: Select all
:: for /F ... do set /A "hours=1%%~a-100", "minutes=1%%~b-100", "seconds=1%%~c-100"
set /A "hours=109-100", "minutes=108-100", "seconds=109-100"
penpen
Re: error in date time calculations
Jorgegs wrote:Sorry I do'nt know how to insert the images. But if necessary I can send.
Post your image to http://imgur.com/ and put the direct link into image tags like this, but remove the spaces.
[ img ]http://imgur.com/23456[ /img ]
penpen is on the ball, but I'd be interested to know how the task needs to use the times as there may be more robust ways to solve this.
Re: error in date time calculations
Thanks Foxidrive
I put the image with a correct functional
and
the same with error marked with red circle
The number of files are correct, there is one more due to the register of the action in the prior operation
You can see the difference of time between both identical procedures
If the time calculations works correctly are all OK.
When not, is a big disaster.
imgur.com user details removed
I think this help you to understand my problem
I put the image with a correct functional
and
the same with error marked with red circle
The number of files are correct, there is one more due to the register of the action in the prior operation
You can see the difference of time between both identical procedures
If the time calculations works correctly are all OK.
When not, is a big disaster.
imgur.com user details removed
I think this help you to understand my problem
-
- Expert
- Posts: 961
- Joined: 15 Jun 2012 13:16
- Location: Italy, Rome
Re: error in date time calculations
The error is on calculous.
post the code that calculate elapsed time.
I use this and this is error free.
if you want second elapsed you may divide variable "a" by 100
einstein1969
post the code that calculate elapsed time.
I use this and this is error free.
Code: Select all
rem start time watch
set t1=%time: =0%
rem do some work.....
rem calculate centisecond elapsed
for /F "tokens=1-8 delims=:.," %%a in ("%t1%:%time: =0%") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31)&8640000"
echo time elapsed:%a%cs
if you want second elapsed you may divide variable "a" by 100
einstein1969
Re: error in date time calculations
Thank you Einstein1969
It Works !!!!
I try it and repeat the same operation 6 times with different elapsed results.
1 elapsed time 7307 cs 73 sec
2 elapsed time 3930 cs 39 sec
3 elapsed time 3428 cs 34 sec
4 elapsed time 7533 cs 75 sec
5 elapsed time 3637 cs 36 sec
In this cases there is a small 2 or 3 sec. with my system calculations, which is perfect.
I do'nt understand the different values in your system, from 1 and 4 with the values of 2, 3 and 5.
There is a big difference.
And when I try to make the same, launching the batch at start time 7:09
I got the message with both calculations systems in the same batch.
Número no valido. Las constantes numéricas son decimales (17)
hexadecimales (0x11), u ottales (021)
and of course, in this case, all the recorded data were wrong, and wrong the results of the depending secondary processes.
This message appears ONLY some time, at the moment when I start the Batch, without any further calculations,
only taking the time and date, from DATE and TIME. SET jgATIME=%TIME% ... SET jgAHOR=%jgATIME:~0,2% ....
This "only some time" is what I do'nt understand.
And in this case in the parallel with both calculations systems in the same batch
I got with your system elapsed time 4635 cs 46 sec. which can be OK according with the other examples 1 to 5
and by my system 8 sec. Which is wrong.
I understand that is imposible to get exactly the same. I do'nt search this,
but are the big differences possible ?
Which will be the effect by a elapsed time from 21 hours, minutes and seconds ?
In any case, my friend, thank you very much for your BIG help
Jorgegs
It Works !!!!
I try it and repeat the same operation 6 times with different elapsed results.
1 elapsed time 7307 cs 73 sec
2 elapsed time 3930 cs 39 sec
3 elapsed time 3428 cs 34 sec
4 elapsed time 7533 cs 75 sec
5 elapsed time 3637 cs 36 sec
In this cases there is a small 2 or 3 sec. with my system calculations, which is perfect.
I do'nt understand the different values in your system, from 1 and 4 with the values of 2, 3 and 5.
There is a big difference.
And when I try to make the same, launching the batch at start time 7:09
I got the message with both calculations systems in the same batch.
Número no valido. Las constantes numéricas son decimales (17)
hexadecimales (0x11), u ottales (021)
and of course, in this case, all the recorded data were wrong, and wrong the results of the depending secondary processes.
This message appears ONLY some time, at the moment when I start the Batch, without any further calculations,
only taking the time and date, from DATE and TIME. SET jgATIME=%TIME% ... SET jgAHOR=%jgATIME:~0,2% ....
This "only some time" is what I do'nt understand.
And in this case in the parallel with both calculations systems in the same batch
I got with your system elapsed time 4635 cs 46 sec. which can be OK according with the other examples 1 to 5
and by my system 8 sec. Which is wrong.
I understand that is imposible to get exactly the same. I do'nt search this,
but are the big differences possible ?
Which will be the effect by a elapsed time from 21 hours, minutes and seconds ?
In any case, my friend, thank you very much for your BIG help
Jorgegs
Re: error in date time calculations
Jorgegs wrote:If the time calculations works correctly are all OK.
When not, is a big disaster.
imgur.com user details removed
I removed your user details at imgur.com
It can be a free service with no need for an account if your pictures are public and there is no need to delete them.
Even with no account a delete link also appears with each image and can be saved to use later on.
In your own account you should be able to share images, and only post the link to the image itself.
Re: error in date time calculations
Thank you "foxidrive"
It was the first time I use the ingmur service.
Could you see the sended images ?
Which are the numbers in time calculations, who causes possible problems ?
0, 8 , 9, space ???
The system proposed by Einstein1969, Works perfect.
In "my system calculations"
When at the end I reconvert from seconds to h:m:s y do'nt divide by 60......
To bypass a posible problem, I subtract in a loop counting the times and the rest is for the next minutes or at end, are de seconds. Which is the same as a división and I do'nt have problems with 0
Is there a for command like the "einstein1969" proposed system for the initial convertion from h:m:s to sec.
for convert from seconds to h:m:s
I need only seconds, I do'nt need cs.
I understand the enormous possibilities of the command "for".
But his use is very complicated for me.
And my "last" question.
In my installed W7 ultimate spanish (32 bits)
If day less 10 the returned DATE is for ex. 02/11/2016 dd/mm/yyyy
If hour less 10 the returned TIME is for ex. 2:11:34,22
It is posible to get it with 0 first, like 02:11:34,22 ???
without changing the rest of the system commands ????
Or may I togled it any time, if posible ????
Thanks to all
Jorgegs
It was the first time I use the ingmur service.
Could you see the sended images ?
Which are the numbers in time calculations, who causes possible problems ?
0, 8 , 9, space ???
The system proposed by Einstein1969, Works perfect.
In "my system calculations"
When at the end I reconvert from seconds to h:m:s y do'nt divide by 60......
To bypass a posible problem, I subtract in a loop counting the times and the rest is for the next minutes or at end, are de seconds. Which is the same as a división and I do'nt have problems with 0
Is there a for command like the "einstein1969" proposed system for the initial convertion from h:m:s to sec.
for convert from seconds to h:m:s
I need only seconds, I do'nt need cs.
I understand the enormous possibilities of the command "for".
But his use is very complicated for me.
And my "last" question.
In my installed W7 ultimate spanish (32 bits)
If day less 10 the returned DATE is for ex. 02/11/2016 dd/mm/yyyy
If hour less 10 the returned TIME is for ex. 2:11:34,22
It is posible to get it with 0 first, like 02:11:34,22 ???
without changing the rest of the system commands ????
Or may I togled it any time, if posible ????
Thanks to all
Jorgegs
Re: error in date time calculations
penpen replied under your first post, Jorgegs.
It is the Octal number system causing the problem, where those numbers are not legitimate.
The way the set /a command works is a little bit odd in that way, and the solution is to add 100 (adding a 1 before the two digit number) and take 100 away again in the calculation.
set /a number=108 + 1 - 100
to give you 9 without an error. But it always requires the leading zero or the numbers will be wrong.
Try this and the error will appear. Take the 0 away and try it again.
set /a number=08 + 1
It is the Octal number system causing the problem, where those numbers are not legitimate.
The way the set /a command works is a little bit odd in that way, and the solution is to add 100 (adding a 1 before the two digit number) and take 100 away again in the calculation.
set /a number=108 + 1 - 100
to give you 9 without an error. But it always requires the leading zero or the numbers will be wrong.
Try this and the error will appear. Take the 0 away and try it again.
set /a number=08 + 1
-
- Expert
- Posts: 961
- Joined: 15 Jun 2012 13:16
- Location: Italy, Rome
Re: error in date time calculations
this calculate seconds:
the command:
return 02:xx:yy,zz if there is a space " 2:xx:yy,zz"
Code: Select all
rem start time watch
set t1=%time: =0%
rem do some work.....
rem calculate second elapsed
for /F "tokens=1-8 delims=:.," %%a in ("%t1%:%time: =0%") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31)&8640000, a/=100"
echo time elapsed:%a% seconds
the command:
Code: Select all
set t1=%time: =0%
return 02:xx:yy,zz if there is a space " 2:xx:yy,zz"
Re: error in date time calculations
Thanks einstein1969
I submit to you:
with the new proposed for ........., a/=100
I get time elapsed=:-352749
with the first solution for .....
time elapsed %a%cs and after dividing by 100
is correct and I get time elapsed=:8
I do'nt understand why The last proposed for.....,a/=100 , do'nt work correctly.
Thanks for the easy proposed solution to get 0 in hour, when hour less 10.
I submit to you:
with the new proposed for ........., a/=100
I get time elapsed=:-352749
with the first solution for .....
time elapsed %a%cs and after dividing by 100
is correct and I get time elapsed=:8
I do'nt understand why The last proposed for.....,a/=100 , do'nt work correctly.
Thanks for the easy proposed solution to get 0 in hour, when hour less 10.
-
- Expert
- Posts: 961
- Joined: 15 Jun 2012 13:16
- Location: Italy, Rome
Re: error in date time calculations
strange negative result...
when you test use "echo on" for debug porpouse. Than post here.
This is a variation that ROUND the centisecond results to second:
For convert in Hour:Mnutes:Seconds is simple but i'll working tomorrow. Now is later.
EDIT:done!
when you test use "echo on" for debug porpouse. Than post here.
This is a variation that ROUND the centisecond results to second:
Code: Select all
@echo off
rem start time watch
set t1=%time: =0%
rem do some work.....
timeout 4
rem calculate second elapsed
for /F "tokens=1-8 delims=:.," %%a in ("%t1%:%time: =0%") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31)&8640000, a=(a+50)/100"
echo time elapsed:%a% seconds
pause
For convert in Hour:Mnutes:Seconds is simple but i'll working tomorrow. Now is later.
EDIT:done!
Code: Select all
set /A "H=a/3600, r=a %% 3600, m=r/60, s=a %% 60"
echo elapsed %H%:%M%:%S%
Re: error in date time calculations
Thanks for the solutions
But using all, I get the problem when
origen beginning date (example year:month/time) 2016/12 23:09:08,33
and the end time is greater in date, and less in time
example 2017/01 09:08:09,54
When the process runs by night and pass midnight
In this case, is there some solution to calculate the seconds for the beginning and for the end
not over 32 bits limits calculations ???
I also try with no good results, the conversión to julian date.
Thanks in advance for your help
Jorgegs
But using all, I get the problem when
origen beginning date (example year:month/time) 2016/12 23:09:08,33
and the end time is greater in date, and less in time
example 2017/01 09:08:09,54
When the process runs by night and pass midnight
In this case, is there some solution to calculate the seconds for the beginning and for the end
not over 32 bits limits calculations ???
I also try with no good results, the conversión to julian date.
Thanks in advance for your help
Jorgegs
Re: error in date time calculations
Thank you penpen
for the explanation about the calculation octal error
Your solution is very good.
I have tried in a part of my long batch file, and the result is optimal.
I must change forward all the other situations in my batch file.
My problem was also, because when I use set /a or set var with %var%
I never know the content of the var value to put in the new var.
And some times I get 8 or 9 comming in.
I must change to 08 or 09 and adding 100 when set /a and substract later 100
I know now, that it is not only for time calculations.
But I have learned a lot from all you.
Only the command FOR, seems me for the moment to complicated.
I will work forward and tell you the news.
In any case thank you very much for your estimable help.
Jorgegs
for the explanation about the calculation octal error
Your solution is very good.
I have tried in a part of my long batch file, and the result is optimal.
I must change forward all the other situations in my batch file.
My problem was also, because when I use set /a or set var with %var%
I never know the content of the var value to put in the new var.
And some times I get 8 or 9 comming in.
I must change to 08 or 09 and adding 100 when set /a and substract later 100
I know now, that it is not only for time calculations.
But I have learned a lot from all you.
Only the command FOR, seems me for the moment to complicated.
I will work forward and tell you the news.
In any case thank you very much for your estimable help.
Jorgegs
-
- Expert
- Posts: 961
- Joined: 15 Jun 2012 13:16
- Location: Italy, Rome
Re: error in date time calculations
Jorgegs wrote:Thanks for the solutions
But using all, I get the problem when
origen beginning date (example year:month/time) 2016/12 23:09:08,33
and the end time is greater in date, and less in time
example 2017/01 09:08:09,54
When the process runs by night and pass midnight
In this case, is there some solution to calculate the seconds for the beginning and for the end
not over 32 bits limits calculations ???
I also try with no good results, the conversión to julian date.
Thanks in advance for your help
Jorgegs
My calcoluos get the different time at one day only. If begin time was yesterday at 23 and end time is todayat 09 the result
is negative, but my formulas add one day "a+=(a>>31)&8640000" and get the right results.