# Date Comparison and Manipulation Functions?

W. eWatson notvalid2 at sbcglobal.net
Tue Aug 26 02:55:14 CEST 2008

```zuul at ferg.org wrote:
> check out Pyfdate: http://www.ferg.org/pyfdate
>
> from pyfdate import *
>
> 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
It looks good. Thanks.

--