0

Here is my program:

import datetime

b=input()
a = datetime.date(b)-datetime.datetime.now().date()

print(a)

When I enter the date 2015,2,2, or some another, I have a problem

Traceback (most recent call last):
  File "", line 4, in <module>
    a = datetime.date(b)-datetime.datetime.now().date()
TypeError: an integer is required

How to input the date right? I tried 2015-2-2 and 2015.2.2 and 2015-2-2 and other versions. But nothing works :(

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Kitty
  • 11
  • 1
  • 4

1 Answers1

1

datetime.date requires 3 int arguments and you are passing a touple

Extract the ints from the tuple using an index to grab each position

import datetime

b=input()

a = datetime.date(b[0],b[1],b[2])-datetime.datetime.now().date()

print(a)

Example

b = input()

2015,4,4

a = datetime.date(b[0],b[1],b[2]) - datetime.datetime.now().date() 

print(a)

503 days, 0:00:00

Szymon
  • 42,577
  • 16
  • 96
  • 114
Miguel Z
  • 11
  • 1
  • 1
    I'm sorry, but something is wrong...:( 2015,4,4 Traceback (most recent call last): File "", line 5, in a = datetime.date(b[0],b[1],b[2])-datetime.datetime.now().date() TypeError: an integer is required – Kitty Nov 18 '13 at 00:15