confused on calculating date difference in days.
Shane Geiger
sgeiger at ncee.net
Tue Oct 16 10:17:41 EDT 2007
# Example
import datetime
def days_old(birth_year=1974,birth_month=12,birth_day=7):
return (datetime.date.today() -
datetime.date(birth_year,birth_month,birth_day) ).days
>>> days_old()
12000
krishnakant Mane wrote:
> hello,
> thanks all of you for providing valuable help.
> right now I am confused about the delta object.
> how can I extract the difference between two dates in terms of day
> using the delta object?
> I tried reading the python docs but did not understand the concept of
> delta object and how can I measure the difference in terms of days
> between two dates.
> I expect that the days would be integers.
> secondly the format of my date is actually "16/10/2007", and this is
> all in varchar field inside a postgresql database.
> I understand that datetime.datetime.strptime would convert this string
> "16/10/2007" into a date object which I can then compare with the
> current date created by datetime.now().
> is that right?
> if yes then please explain me how I can get the delta object to give
> me results in days.
> regards,
> Krishnakant.
>
--
Shane Geiger
IT Director
National Council on Economic Education
sgeiger at ncee.net | 402-438-8958 | http://www.ncee.net
Leading the Campaign for Economic and Financial Literacy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sgeiger.vcf
Type: text/x-vcard
Size: 310 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20071016/9d477366/attachment.vcf>
More information about the Python-list
mailing list