Author |
Message |
ntba1
|
Posted: Tue Apr 18, 2006 3:52 pm Post subject: Dates and times |
|
|
Hi I've just signed on to CompSci looks like a great place. I've been lurking around and need some help with a certain Turing function. I've been searching and read and well can't find anything on how to use Date/Time in turing. The perticular problem is how would I go about subtracting two times from each other or even dates? Thanks |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Tue Apr 18, 2006 4:11 pm Post subject: (No subject) |
|
|
Welcome!
There are a few time related functions in Turing, so you'll have to be very specific as to what you are attempting to accomplish. If what you are looking for is a timer, then you'll want to research Time.Elapsed, which returns the amount of milliseconds that the program has been running. If you simply need to know the time of the year, Time.Date will be of help. Finally, if as I suspect you are trying to find the difference between two dates, you'll have to try Time.PartsSec() and do some math on the resulting variables. Just post if you need any more assistance in your endeavours. |
|
|
|
|
![](images/spacer.gif) |
ntba1
|
Posted: Wed Apr 19, 2006 4:30 pm Post subject: (No subject) |
|
|
Thank you for your reply, well my problem in detail is that I need to find the difference between two times(ie 13:00 and 14:00 = 1 hour etc.) for a program I am writing that will ask the user for their start time and finish time and distance to calculate their average speed. I am having a difficult time figuring out how to write it so that it will tell me the difference between the two times, I have the rest down. And here's the code so far but it's mostly variables and the questions.
code: |
var StartTimeHr:int
var StartTimeMin:int
var EndTimeHr:int
var EndTimeMin:int
var Distance:real
put "At what time did you start?"
put "Hours:"
get StartTimeHr
put "Minutes:"
get StartTimeMin
put "When did your trip end?"
put "Hours:"
get EndTimeHr
put "Minutes:"
get EndTimeMin
put "How far did you travel in KM?"
get Distance
|
|
|
|
|
|
![](images/spacer.gif) |
ntba1
|
Posted: Wed Apr 19, 2006 4:32 pm Post subject: (No subject) |
|
|
I also forgot to mention I am using Turing 6.5 for DOS and have no way to upgrade or use the Windows based Turing. I know it sucks. |
|
|
|
|
![](images/spacer.gif) |
ntba1
|
Posted: Wed Apr 19, 2006 4:36 pm Post subject: (No subject) |
|
|
(Grrrr I don't like how I'm not able to edit posts as I keep remembering things to say) I've looked around some sites and have seen some people converting the times into minutes or seconds to perform calculations on them to get differences. How would I go about implementing this? |
|
|
|
|
![](images/spacer.gif) |
NikG
|
Posted: Wed Apr 19, 2006 10:58 pm Post subject: (No subject) |
|
|
Since I'm assuming with DOS Turing you don't have the Time module, you could keep 2 variables for total seconds and use them to find the difference. Then it's just a matter of converting the result back into hours/minutes/seconds. |
|
|
|
|
![](images/spacer.gif) |
codemage
![](http://usera.imagecave.com/codemage/codemage-small.gif)
|
Posted: Thu Apr 20, 2006 8:41 am Post subject: (No subject) |
|
|
As a matter of reference, only the newer versions have time, and I think the module was included but broken in 4.0.3 |
|
|
|
|
![](images/spacer.gif) |
ntba1
|
Posted: Thu Apr 20, 2006 2:41 pm Post subject: (No subject) |
|
|
Well thank you all for your replys but it took some time but I got it I will post the code for those who want to see it:
code: |
var StartTimeHr:real
var StartTimeMin:real
var EndTimeHr:real
var EndTimeMin:real
var Distance:real
var TimeInMins:real
var Average:real
var Hours:real
put "At what time did you start?(24h time)"
put "Hours:"..
get StartTimeHr
put "Minutes:"..
get StartTimeMin
put "When did your trip end?"
put "Hours:"..
get EndTimeHr
put "Minutes:"..
get EndTimeMin
put "How far did you travel in KM?"..
get Distance
put " "
put "You traveled for: ", EndTimeHr - StartTimeHr," hours and ", EndTimeMin -
StartTimeMin, " minutes"
put " "
put "You traveled: ",Distance," KM"
TimeInMins := (EndTimeHr - StartTimeHr)*60 + (EndTimeMin - StartTimeMin)
put " "
put "Your total time in minutes is: ", TimeInMins
Hours := TimeInMins / 60
Average := Distance / Hours
put " "
put "Your average speed was: ", Average," KM/h"
|
Basically you enter the start time and end time in 24 hour time, it subtracts the difference, turns that difference to minutes then converts it to hours and you get the average by dividing distance by the hours. It even works fine when the number of minutes in the end time is lower then the start time. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
NikG
|
Posted: Thu Apr 20, 2006 3:19 pm Post subject: (No subject) |
|
|
Sorry ntba1, but you've got a mistake.
Try this input: start: 8h, 30min; end: 9h, 15min; distance:100
Rather what you should do is, as I said before, is keep 2 variables (StartTimeMin/EndTimeMins). Once you get the start time, update StartTimeMin with the total minutes. Once you get the end time, update EndTimeMin with the total minutes. Subtract the 2 for the difference, and then, convert it back to hours/minutes.[/code] |
|
|
|
|
![](images/spacer.gif) |
NikG
|
Posted: Thu Apr 20, 2006 3:21 pm Post subject: (No subject) |
|
|
My mistake, what you have isn't wrong, just weird!
Why would you want to say I travelled for 1 hour and -15 minutes? You should be saying I travelled for 45 minutes. |
|
|
|
|
![](images/spacer.gif) |
ntba1
|
Posted: Thu Apr 20, 2006 3:55 pm Post subject: (No subject) |
|
|
Well I had that output for testing and yes I know it is weird and I really don't know how it all worked I was thinking that if the number of minutes in the EndTime were less than the number of StartTime minutes that the output would be wierd but I only found out once I finished the program that it worked perfect. |
|
|
|
|
![](images/spacer.gif) |
NikG
|
Posted: Thu Apr 20, 2006 9:56 pm Post subject: (No subject) |
|
|
Ummm, but it's not perfect!
NikG wrote: Why would you want to say I travelled for 1 hour and -15 minutes? You should be saying I travelled for 45 minutes. |
|
|
|
|
![](images/spacer.gif) |
|