forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


time calcuations
Goto page 1, 2  Next
 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
Serge
Professional Member
Professional Member


Joined: 04 Mar 2002
Posts: 1480
Location: Australia

PostPosted: Fri Oct 18, 2002 11:02 pm    Post subject: time calcuations Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Fri Oct 18, 2002 11:14 pm    Post subject: Reply with quote

Could ya post the code you're using?

Are you just wanting the days difference? Or hours etc.?

Cheers, Mac Smile

_________________
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
View user's profile Send private message Send e-mail
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Fri Oct 18, 2002 11:44 pm    Post subject: Reply with quote

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 Smile

_________________
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
View user's profile Send private message Send e-mail
Serge
Professional Member
Professional Member


Joined: 04 Mar 2002
Posts: 1480
Location: Australia

PostPosted: Fri Oct 18, 2002 11:53 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
Serge
Professional Member
Professional Member


Joined: 04 Mar 2002
Posts: 1480
Location: Australia

PostPosted: Fri Oct 18, 2002 11:58 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Sat Oct 19, 2002 12:22 am    Post subject: Reply with quote

Hey Serge, Smile

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... Confused

Cheers, Mac Smile

_________________
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
View user's profile Send private message Send e-mail
moke
Contributor
Contributor


Joined: 02 Jan 2002
Posts: 162

PostPosted: Sat Oct 19, 2002 3:03 am    Post subject: Reply with quote

Hi Serge Smile,

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
View user's profile Send private message Send e-mail
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Sat Oct 19, 2002 3:24 am    Post subject: Reply with quote

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. Smile

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... Wink

Cheers, Mac Smile

_________________
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
View user's profile Send private message Send e-mail
moke
Contributor
Contributor


Joined: 02 Jan 2002
Posts: 162

PostPosted: Sat Oct 19, 2002 3:48 pm    Post subject: Reply with quote

Hey Mac, Smile

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.

Smile
moke
Back to top
View user's profile Send private message Send e-mail
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Sat Oct 19, 2002 9:03 pm    Post subject: Reply with quote

Gotchya. Wink

I got the format idea from his example though...

Cheers, Mac Smile

_________________
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
View user's profile Send private message Send e-mail
Serge
Professional Member
Professional Member


Joined: 04 Mar 2002
Posts: 1480
Location: Australia

PostPosted: Sat Oct 19, 2002 11:27 pm    Post subject: Reply with quote

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). Sad Sad Sad

Thanks for all your help Very Happy Very Happy Very Happy

Serge

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
moke
Contributor
Contributor


Joined: 02 Jan 2002
Posts: 162

PostPosted: Sun Oct 20, 2002 3:53 am    Post subject: Reply with quote

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. Smile

moke
Back to top
View user's profile Send private message Send e-mail
Serge
Professional Member
Professional Member


Joined: 04 Mar 2002
Posts: 1480
Location: Australia

PostPosted: Sun Oct 20, 2002 7:48 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
moke
Contributor
Contributor


Joined: 02 Jan 2002
Posts: 162

PostPosted: Sun Oct 20, 2002 2:53 pm    Post subject: Reply with quote

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 Confused but If the "-" in the exponential is causing the glitch this appears to work around it.

moke
Back to top
View user's profile Send private message Send e-mail
moke
Contributor
Contributor


Joined: 02 Jan 2002
Posts: 162

PostPosted: Sun Oct 20, 2002 3:01 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group