Computer Science Canada

Need some help using the Time.Date and string functions

Author:  dajoubert12 [ Sat Oct 12, 2013 4:25 pm ]
Post subject:  Need some help using the Time.Date and string functions

[size=14][b]What is it you are trying to achieve?
I am trying to calculate the number of seconds, minutes, hours, days and years the user has been alive.


[size=14][b]What is the problem you are having?
I need the user to input their birthday in the format of dd mmm yy (ex. 03 Jun 92) in string form and calculate how long they've been alive.


[size=14][b]Describe what you have tried to solve this problem
I am fairly new to turing so I am not sure how to do this.


[size=14][b]Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Time.Date, :string

Turing:




[size=14][b]Please specify what version of Turing you are using
4.1.1

Author:  DemonWasp [ Sat Oct 12, 2013 6:08 pm ]
Post subject:  RE:Need some help using the Time.Date and string functions

Look at Time.DateSec to convert your format "03 Jun 92" into seconds (since the "epoch", defined as 00:00:00 Jan 1st 1970 GMT). See http://compsci.ca/holtsoft/doc/time_datesec.html

Then you can use Time.Sec to get the current date in seconds (since the same epoch as above). See http://compsci.ca/holtsoft/doc/time_sec.html

There is a very simple bit of math you can use to figure out how many seconds are between (birthday) and (now). What is it?

Once you have that number of seconds, you can use Time.SecParts to get the number of years, months, days, hours, minutes and seconds elapsed. See http://compsci.ca/holtsoft/doc/time_secparts.html

There is a key limitation to using dates that are stored as "the number of seconds since the epoch". What is it? (Hint: try entering your parents' or grandparents' birthdates).

Author:  dajoubert12 [ Sun Oct 13, 2013 5:19 pm ]
Post subject:  Re: Need some help using the Time.Date and string functions

Ok thanks. A problem I just encountered is that when the user inputs their birthday and I only want to use one variable, it only takes the day of the month entered because of the space in between the days, months, and year of the person's birthday. Is there a code I can use so it takes all three parts in one string variable?

Author:  DemonWasp [ Sun Oct 13, 2013 6:17 pm ]
Post subject:  RE:Need some help using the Time.Date and string functions

Can you post the code you're using (in [syntax=" turing "] [ /syntax] blocks), plus your input, expected output, and actual output?

Author:  dajoubert12 [ Sun Oct 13, 2013 7:24 pm ]
Post subject:  Re: Need some help using the Time.Date and string functions

Sorry I don't understand what you're asking for. What sort of code are you looking for?

Author:  Raknarg [ Sun Oct 13, 2013 8:11 pm ]
Post subject:  RE:Need some help using the Time.Date and string functions

Have you written any code?

Author:  dajoubert12 [ Mon Oct 14, 2013 5:29 am ]
Post subject:  Re: Need some help using the Time.Date and string functions

Sorry I don't understand what you're asking for. What sort of code are you looking for?

Author:  Nathan4102 [ Mon Oct 14, 2013 8:32 am ]
Post subject:  RE:Need some help using the Time.Date and string functions

The code you typed into Turing,below the run button. You said you're getting incorrect output, so you have typed some code, right?

Author:  Raknarg [ Mon Oct 14, 2013 7:45 pm ]
Post subject:  RE:Need some help using the Time.Date and string functions

We don't write code for you, we like you to try on your own first, and then come to us for help. try something out first, and show us what you did. Unless you're really, really stuck


: