1.3 datetime -- Compatibility code providing date and time classes for Python 2.2 users

The following classes provide a subset of the functionality of the Python 2.3 date, time and datetime Objects. If you want to do sophisticated date and time classes is it is reccommended that you use Python 2.3. These classes are designed only so that Python 2.2 users can still use date and time functionality in the web.database module.

Note: It should be noted that although the time and datetime classes have the ability to support microseconds, the web.database module only deals in whole seconds since some of the underlying databases do not support microseconds.

class date( year, month, day)

A date object represents a date (year, month and day) in an idealized calendar, the current Gregorian calendar indefinitely extended in both directions. January 1 of year 1 is called day number 1, January 2 of year 1 is called day number 2, and so on. This matches the definition of the "proleptic Gregorian" calendar in Dershowitz and Reingold's book Calendrical Calculations, where it's the base calendar for all computations. See the book for algorithms for converting between proleptic Gregorian ordinals and many other calendar systems.

All arguments are required. Arguments may be ints or longs, in the following ranges:

If an argument outside those ranges is given, ValueError is raised.

Instance Attributes:

year
Between MINYEAR and MAXYEAR inclusive.
month
Between 1 and 12 inclusive.
day
Between 1 and the number of days in the given month of the given year.

class time( [hour=0][,minute=0][,second=0][,microsecond=0])

A time object represents a (local) time of day, independent of any particular day.

All arguments are required. Arguments may be ints or longs, in the following ranges:

If an argument outside those ranges is given, ValueError is raised.

Instance Attributes:

hour
In range(24).
minute
In range(60).
second
In range(60).
microsecond
In range(1000000).

class datetime( year, month, day[,hour=0][,minute=0][,second=0][,microsecond=0])

A datetime object is a single object containing all the information from a date object and a time object. Like a date object, datetime assumes the current Gregorian calendar extended in both directions; like a time object, datetime assumes there are exactly 3600*24 seconds in every day.

All arguments are required. Arguments may be ints or longs, in the following ranges:

If an argument outside those ranges is given, ValueError is raised.

Instance Attributes:

year
Between MINYEAR and MAXYEAR inclusive.
month
Between 1 and 12 inclusive.
day
Between 1 and the number of days in the given month of the given year.
hour
In range(24).
minute
In range(60).
second
In range(60).
microsecond
In range(1000000).

All classes have the following class methods:

now( )
Returns a datetime.datetime object representing the current date and time

strftime( format)
Format the date using standard time module string format strings:
%a Locale's abbreviated weekday name.   
%A Locale's full weekday name.   
%b Locale's abbreviated month name.   
%B Locale's full month name.   
%c Locale's appropriate date and time representation.   
%d Day of the month as a decimal number [01,31].   
%H Hour (24-hour clock) as a decimal number [00,23].   
%I Hour (12-hour clock) as a decimal number [01,12].   
%j Day of the year as a decimal number [001,366].   
%m Month as a decimal number [01,12].   
%M Minute as a decimal number [00,59].   
%p Locale's equivalent of either AM or PM.   
%S Second as a decimal number [00,61]. (1) 
%U Week number of the year (Sunday as the first day of the week)
   as a decimal number [00,53]. All days in a new year preceding
   the first Sunday are considered to be in week 0.   
%w Weekday as a decimal number [0(Sunday),6].   
%W Week number of the year (Monday as the first day of the week)
   as a decimal number [00,53]. All days in a new year preceding
   the first Monday are considered to be in week 0.   
%x Locale's appropriate date representation.   
%X Locale's appropriate time representation.   
%y Year without century as a decimal number [00,99].   
%Y Year with century as a decimal number.   
%Z Time zone name (no characters if no time zone exists).   
%% A literal "%" character. 

For example:

>>> datetime.datetime(2004,5,3,10,30,50).strftime('%x-%X')
'05/03/04-10:30:50'

timetuple( )
Returns a basic time tuple for the date. Warning: The last 6 entries in the tuple returned from this function are obtained from time.localtime() and do not represent anything.

isoformat( )
Return the date as a standard SQL string of the format. Warning: microseconds are ignored.
>>> import web, datetime
>>> datetime.date(2004,5,3).isoformat()
'2004-05-03'
>>> datetime.time(10,30,50,9).isoformat() # Microseconds are ignored
'10:30:50'
>>> datetime.datetime(2004,5,3,10,30,50).isoformat()
'2004-05-03 10:30:50'



Subsections