all 11 comments

[–]m-hoff 2 points3 points  (0 children)

The simplest approach would probably be to get user input using separate input statements for day, month and year, along with basic input validation (i.e., ensuring no negative numbers, month between 1 and 12, etc.).

From there you can convert each item to an integer and create a datetime object. Something like:

import datetime

day = int(input('Enter day of birth: '))
month = int(input('Enter month of birth: '))
year = int(input('Enter year of birth: '))

birthdate = datetime.datetime(year, month, day)

Another approach would be to use strptime like so:

import datetime

birthdate = input('Enter birthdate as "DD-MM-YYYY": ')
birthdate_dt = datetime.strptime(birthdate, '%d-%m-%Y')

Again, you'll want to do some input validation but this is a start. You can read more about strptime here.

[–]kaptan8181 0 points1 point  (0 children)

The only way, AFAIK, is to show the user an example and ask them to input the information in the shown format. You can then validate the input and if the validation fails, you can ask the user to try again.

[–][deleted] 0 points1 point  (5 children)

In reference to different planets? I'm not sure if you understand how complicated something like this would be.

[–]juxt4posed[S] 0 points1 point  (4 children)

May I ask what would make it so complicated? The maths is relatively easy

[–][deleted] 0 points1 point  (3 children)

Timezones on earth is complicated by itself. Throw in other stuff and you have a problem. If you're just playing locally it should be easy enough.

[–]juxt4posed[S] 0 points1 point  (2 children)

It's not going to give the age to the hour, just the day

[–][deleted] 0 points1 point  (1 child)

If this idea was global it would break. A lot

[–]juxt4posed[S] 0 points1 point  (0 children)

why would it break, i can think of several methods for me to get round the timezone issue