date and time comparison how to

Dave Angel d at davea.name
Tue Oct 30 05:35:13 EDT 2012


On 10/30/2012 12:20 AM, noydb wrote:
> On Monday, October 29, 2012 11:11:55 PM UTC-4, Dave Angel wrote:
>> On 10/29/2012 10:13 PM, noydb wrote:
>>
>>> I guess I get there eventually!  
>>
>>> <snip>
>>
>>
> 
> okay, I see.
> But for the user supplied date... I'm not sure of the format just yet... testing with a string for now (actual date-date might be possible, tbd later), so like '10292012213000' (oct 29, 2012 9:30pm).  How would you get that input into a format to compare with dt above?
> 

See http://docs.python.org/2/library/datetime.html

There are a number of constructors for datetime.  For example,

now = datetime.datetime.now()

spec = datetime.strptime(datstring, format)

spec = datetime.datetime(year, month, day[, hour[, minute[, second[,
microsecond)

In each case, you have an optional tz for timezone.  Or if possible, use
utc versions of these functions to get "greenwich" times.  tz is one of
the biggest pains, and the quirks vary between operating systems and
filesystems.  If possible in your environment, use   utcnow,
utcfromtimestamp, etc.


-- 

DaveA



More information about the Python-list mailing list