| View previous topic :: View next topic |
| Author |
Message |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Fri Oct 18, 2002 11:02 pm Post subject: time calcuations |
|
|
In one of my programs, i do a time calculation by storing the current date and time using @datetime() into a variable and then later on doing the same thing with a different variable. Then i take the difference between the 2 variables and i have @datetime() show me the time difference.
The problem that i have is that it works well as long as the date separator is a "\". If i use "-" as the date separator, then VDS gives me an error saying "incorrect date format" of something like that.
Anybody have any idea what is going on there? I would have thought that VDS would have been able to cope with any date format that Windows uses.
Thanks in advance,
Serge _________________
|
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Fri Oct 18, 2002 11:14 pm Post subject: |
|
|
Could ya post the code you're using?
Are you just wanting the days difference? Or hours etc.?
Cheers, Mac  _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Fri Oct 18, 2002 11:44 pm Post subject: |
|
|
OK, this @datetime() function does the same thing
on my system...
This works:
INFO test @datetime(, 08/10/2002)
This doesn't:
INFO test @datetime(, 08-10-2002)
Kinda strange since other @datetime() functions
seem to work both ways. Maybe this one depends
on the separator used by Windows for different
countries/languages?
Cheers, Mac  _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Fri Oct 18, 2002 11:53 pm Post subject: |
|
|
Here is a copy of the line that does the calculation. It is to display the starting time and then the time difference between the 2 times,
| Code: |
%%new_entry = @datetime(hh:nn:ss am/pm,@item(4)) @datetime(hh:nn:ss,@fsub(@datetime(),@item(4)))
|
and @item(4) contains the previous date/time as follows
| Code: |
list add, 4, @datetime()
|
_________________
|
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Fri Oct 18, 2002 11:58 pm Post subject: |
|
|
Glad to see that you have the same problem Mac.
What would happen then for folks whose Windows International settings used "-" as the date separator?!?!?!
They'd have to change their International settings just to use the @datetime() function of VDS?!?!?!?
I find that rather strange...
Thanks for your help,
Serge _________________
|
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sat Oct 19, 2002 12:22 am Post subject: |
|
|
Hey Serge,
I'm still wondering - where are you using the separators?
This works for less than 24 hr periods without specifying any...
| Code: |
%%start = @datetime()
WAIT 5
%%end = @datetime()
INFO Start = @datetime(hh:nn:ss am/pm,%%start)@cr()End = @datetime(hh:nn:ss am/pm,%%end)@cr()@cr()Diff = @datetime(hh:nn:ss, @fsub(%%end,%%start))
|
Or am I missing something here...
Cheers, Mac  _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
moke Contributor

Joined: 02 Jan 2002 Posts: 162
|
Posted: Sat Oct 19, 2002 3:03 am Post subject: |
|
|
Hi Serge ,
To ask Mac's question a different way (I think). Why don't you use the raw response from @datetime() with no formating or seperators to do your calculation? You can always convert it back to a time after the calculation is done.
| Code: |
%%then = @datetime()
wait 5
%%now = @datetime()
%%diff = @fsub(%%now,%%then)
info raw data = %%diff
info date format @datetime(hh:mm:ss,%%diff)
|
The code should be a little more effiicient by not formatting until you need to return a formatted date. I think this is right but Mac probably knows better than me.
moke |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sat Oct 19, 2002 3:24 am Post subject: |
|
|
Actually moke, I'm kinda in the dark here as to exactly what
he's doing with this, but my point was the same as yours.
As far as your example goes, it may or may not not be
more accurate. While it does take a fraction of time to do
the format, I assume (in my example) the subtraction would
take place first anyway. Otherwise there's nothing to format...
Cheers, Mac  _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
moke Contributor

Joined: 02 Jan 2002 Posts: 162
|
Posted: Sat Oct 19, 2002 3:48 pm Post subject: |
|
|
Hey Mac,
Yeah, I realize that the math would be done first. My comment was really more in reference to Serge's need here. If he doesn't actually need a formatted response and is only looking for the < or > type values or maybe simply checking if there is a difference why format the result at any point during the calculation. I would expect there to be little difference between your example and mine. I was just trying to demonstrate that the result doesn't necessarily need to be in a date format depending upon the application.
moke |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sat Oct 19, 2002 9:03 pm Post subject: |
|
|
Gotchya.
I got the format idea from his example though...
Cheers, Mac  _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Sat Oct 19, 2002 11:27 pm Post subject: |
|
|
Good news - i have found what the problem is.
When you do:
| Code: |
%%start = @datetime()
wait 5
%%end = @datetime()
%%difference = @fsub(%%end,%%start)
|
then %%difference contains the number 5.85648012929596E-5.
If i then do:
| Code: |
%%time = @datetime(hh:nn:ss,%%difference)
|
then,
1. if the Windows date separator is set to "/", then %%time = 00:00:05
2. but if the Windows date separator is set to "-", then i get an error to the effect that %%difference is not a valid date/time. BUT, if i change 5.85648012929596E-5 to 0.0000585648012929596 then %%time gives me the correct answer.
So, if Windows uses "-" as its date separator then %%difference needs to be changed to a decimal number without any exponentials. To do this i used:
| Code: |
%%difference = @format(%%difference,4.9)
|
I can now use this process in my code as it doesn't matter if Windows uses "/" or "-" as i will get the correct answer either way.
I'm sorry to say that none of your ideas mentioned above worked - i tried! They didn't work because each time the answer was as a decimal with an exponential (ie E-5).
Thanks for all your help
Serge _________________
|
|
| Back to top |
|
 |
moke Contributor

Joined: 02 Jan 2002 Posts: 162
|
Posted: Sun Oct 20, 2002 3:53 am Post subject: |
|
|
Interesting problem. How bout using @format() to reduce the number of decimal places before famatting the date. It shouldn't make a big difference unless microseconds are importand to your app.
| Code: |
%%then = @datetime()
wait 5
%%now = @datetime()
%%diff = @fsub(%%now,%%then)
info raw data = %%diff
%%diff2 = @format(%%diff,5.14)
info %%diff2
info date format @datetime(hh:mm:ss,%%diff)
info date format @datetime(hh:mm:ss,%%diff2)
|
Not sure if this does the trick but I hope it helps.
moke |
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Sun Oct 20, 2002 7:48 am Post subject: |
|
|
The problem is not in the number of decimal places but in the answer produced by VDS when you do:
| Code: |
@fsub(%%now,%%then)
|
The answer it produces contains something like "E-5" and it is that part of the answer that @datetime(hh:nn:ss,) does not like when the Windows date separator is "-".
I have no idea why the date separator should influence such calculations as:
| Code: | %%diff = @fsub(%%now,%%then)
...
@datetime(hh:mm:ss,%%diff)
|
but it does.
Thanks for your thoughts,
Serge _________________
|
|
| Back to top |
|
 |
moke Contributor

Joined: 02 Jan 2002 Posts: 162
|
Posted: Sun Oct 20, 2002 2:53 pm Post subject: |
|
|
Serge,
Reducing the number of places after the decimal will, I think, get rid of the exponential. I'm not sure how few decimal places you can do this with safely but 14 seems to work consistently. I would try to use as few as possible though and still obtain a valid response. I may be misunderstanding something here but If the "-" in the exponential is causing the glitch this appears to work around it.
moke |
|
| Back to top |
|
 |
moke Contributor

Joined: 02 Jan 2002 Posts: 162
|
Posted: Sun Oct 20, 2002 3:01 pm Post subject: |
|
|
| Serge, never mind i guess I wasn't reading you post correctly. I see you had already resolved the problem the same way i was suggesting. |
|
| Back to top |
|
 |
|