Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Datetime operations
Message
From
30/10/1997 00:47:27
 
 
To
29/10/1997 16:23:52
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00057210
Message ID:
00057332
Views:
30
>>>>>>Is there a way to subtract one datetime field from another to find the amount of time between them? I asked this question a few weeks ago but my proble then was solvable using seconds(). This time it isn't.
>>>>>
>>>>>I guess you should use functions:
>>>>>Procedure gettime
>>>>>Parameters dt1,dt2
>>>>>return 3600*24*(ttod(dt1)-ttod(dt2)+3600*(hour(dt1)-hour(dt2))+ ;
>>>>>60*(minute(dt1)-minute(dt2))+sec(dt1)-sec(dt2)
>>>>>You can also format returning value back to days:hours:min:sec
>>>>
>>>>Thanks Ed! This code worked almost as is (missing a paren) to return the number of seconds between the parameters. IF you rattled that off of the top of your head, I am truly impressed. Thanks again.
>>>
>>>Erik,
>>>
>>>I am puzzled, why don't you just subtract the two datetime fields. I don't see the need for the function above.
>>>
>>>dt1 is 1997/10/29 12:58:51 PM
>>>dt2 is 1997/10/29 12:58:57 PM
>>>
>>>dt2 - dt1 is 6 (seconds)
>>
>>Evan- you are right... Alex Z. also pointed this out.
>> The reason I asked the question in the first place was that I had tried that before using time(). Well, time returns a string, so subtracting a string from a string doesn't exactly give the results I was looking for. For some reason I was thinking that subtracting datetime fields returned the same results. I am really kicking myself for not just trying it first. Still a pretty fancy (though now irrelevant) piece of code on Edward's part... :-)
>
>The most interesting thing here, that I really tried to test simple subtraction first, when I saw initial question, and it didn't work on my machine! When I saw Alex reply, I tried again and it worked::))

you must believe b4 the functions will work. 8^)
tc
Previous
Reply
Map
View

Click here to load this message in the networking platform