Date Comparison and Manipulation Functions?
W. eWatson
notvalid2 at sbcglobal.net
Mon Aug 25 20:55:14 EDT 2008
zuul at ferg.org wrote:
> 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
It looks good. Thanks.
--
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet
Web Page: <www.speckledwithstars.net/>
More information about the Python-list
mailing list