Python Forum
How do I get rid of certain text
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I get rid of certain text
#3
Some observations:

'Explicit is better than implicit': datetime.datetime.today() says explicitly that I am interested in (to)day. datetime.datetime.now() says implicitly that I am interested in current point of time. You will have correct number of days in both ways but it's zen to signal your intentions explicitly.

Your current way of taking input from user can be optimized. You can ask input once and parse date from that without converting input. There is strptime (string-parse-time) method in datetime. You can do this way:

>>> answer = input('Please enter your birthday in dd/mm/yyyy format: ')
Please enter your birthday in dd/mm/yyyy format:  01/01/2000
>>> birthdate = datetime.datetime.strptime(answer, '%d/%m/%Y')
>>> (datetime.datetime.today() - birthdate).days
6801
You will get ValueError if user input is not in correct format.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
How do I get rid of certain text - by keegan_010 - Aug-14-2018, 09:15 AM
RE: How do I get rid of certain text - by j.crater - Aug-14-2018, 09:24 AM
RE: How do I get rid of certain text - by perfringo - Aug-15-2018, 04:09 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020