Date Comparison and Manipulation Functions?

zuul at ferg.org zuul at ferg.org
Sun Aug 24 23:28:15 EDT 2008


check out Pyfdate: http://www.ferg.org/pyfdate

from pyfdate import *

t = Time().add(hours=14)
print "It is now", t.wdt

datestring1 = "2005/10/05" #year,month,day
datestring2 = "2002/09/22" #year,month,day
datestring3 = "2007/11/11" #year,month,day

year,month,day = numsplit(datestring1)  # split into integers
t1 = Time(year,month,day)
for datestring in (datestring2,datestring1,datestring3):
	year,month,day = numsplit(datestring)
	t2 = Time(year,month,day)

	if t1 > t2:
		print t1.isodate, "is later than  ", t2.isodate
	elif t1 == t2:
		print t1.isodate, "is the same as ", t2.isodate
	elif t1 < t2:
		print t1.isodate, "is earlier than", t2.isodate

print

t1 = Time(2000,2,28)
print "The date after", t1.d, "is", t1.plus(day=1).d
t1 = Time(2001,2,28)
print "The date after", t1.d, "is", t1.plus(day=1).d
t1 = Time(2004,2,28)
print "The date after", t1.d, "is", t1.plus(day=1).d

print
datestring1 = "2005/10/05 20:10:08"
datestring2 = "2005/10/05 20:10:06"
datestring3 = "2005/10/05 20:10:09"

t1 = Time(*numsplit(datestring1))
for datestring in (datestring2,datestring1,datestring3):
	t2 = Time(*numsplit(datestring))

	if t1 > t2:
		print t1.d, t1.civiltime2, "is later than  ", t2.d, t2.civiltime2
	elif t1 == t2:
		print t1.d, t1.civiltime2, "is the same as ", t2.d, t2.civiltime2
	elif t1 < t2:
		print t1.d, t1.civiltime2, "is earlier than", t2.d, t2.civiltime2



More information about the Python-list mailing list