0

hello,
i just want to find difference between two dates interms of days by getting dates as a user input. i tried getting user input using raw_input but it shows some erroe message. can anyone tell me the right coding for this one.urgent please...

2
Contributors
1
Reply
34
Views
4 Years
Discussion Span
Last Post by Gribouillis
1

Use a datetime.timedelta instance to represent the difference between two dates

yA, mA, dA = 1969,7, 21
yB, mB, dB = 2013, 12, 22

import datetime as dt

dateA = dt.date(yA, mA, dA)
dateB = dt.date(yB, mB, dB)
diff = dateB - dateA # a timedelta object
print ("diff is {0} days. (could be negative)".format(diff.days))
print ("and {0} seconds. (nonnegative, less than one day)".format(diff.seconds))
print ("and {0} microseconds. (nonnegative, less than one second)".format(diff.microseconds))

""" my output -->
diff is 16225 days. (could be negative)
and 0 seconds. (nonnegative, less than one day)
and 0 microseconds. (nonnegative, less than one second)
"""

Edited by Gribouillis

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.