Python date and time comparison

Based on this example, I found here I want to get icalendar data and process it. This is my code so far:

from datetime import datetime, timedelta
from icalendar import Calendar
import urllib
import time

ics = urllib.urlopen('https://www.google.com/calendar/ical/xy/basic.ics').read()
ical1 = Calendar.from_ical(ics)
for vevent in ical1.subcomponents:
    if vevent.name == "VEVENT":
        title = str(vevent.get('SUMMARY').encode('utf-8'))
        start = vevent.get('DTSTART').dt   # datetime
        end = vevent.get('DTEND').dt       # datetime

        print title
        print start
        print end
        print type(start)
        print "---"

Gets the title and starts + the end date from my Google calendar. This work and conclusion are as follows:

This is a Test Title
2012-12-20 15:00:00+00:00
2012-12-20 18:00:00+00:00
<type 'datetime.datetime'>
---
Another Title
2012-12-10
2012-12-11
<type 'datetime.date'>
---
    ...

, datetime.datetime datetime.date. , Google 2 ( datetime.date) , . 3 ( datetime.datetime. / 4 . (, ), , ? "" , . " + 4 ", "4 ".

+3
2

. , , โ†’ . () . :

>>> import datetime
>>> datetime.date(2014, 2, 22) == datetime.datetime.now().date()
True
+1

Datetime , : start.date(), : start.date() < datetime.date.today() + datetime.timedelta(4*7)

+1

All Articles