[Tutor] date and time variables
mikalzet@libero.it
mikalzet@libero.it
Sun, 27 Jan 2002 15:05:25 +0100 (CET)
All right, I'm just toying around with my idea (see my previous post on
starting a new project).
So I wrote a very rudimentary piece of code:
class Shift:
def __init__(self, name="None", worker="None", begin="None", end="None"):
self.name = name
self.worker = worker
self.begin = begin
self.end = end
def __str__(self):
return str(self.name) + "\n" + str(self.worker) + "\n" + str(self.begin) + " - " + str(self.end)
def hours(self):
return abs(self.begin - self.end)
Which works if I call it as follows:
newshift = Shift("PN Int mt.","ALZ", 8, 14)
print newshift
print newshift.hours()
However !
My PostgreSQL table at the moment looks something like this:
Field Variable type
Name text
Begin datetime
End datetime
worker char
datetime formats like this:
2002-01-28 14:00:00
I chose datetime instead of an int type variable because I'm sure to need
actual time measurements in future.
Now for the questions:
1) How can I get my Shift class to handle this type of data ? Is there an
analogous data type in python ? Or do I have to 'translate' data to a
different type when reading / writing to postgres ?
2) Where can I find documentation on how to interact with postgres from
python ?
--
Michele Alzetta