473,372 Members | 1,040 Online

# Date Comparison and Manipulation Functions?

Are there some date and time comparison functions that would compare, say,

Is 10/05/05 later than 09/22/02? (or 02/09/22 format, yy/mm/dd)
Is 02/11/07 the same as 02/11/07?

Is 14:05:18 after 22:02:51? (24 hour day is fine)

How about the date after 02/28/04 is 02/29/04, or the date after 09/30/08 is
10/01/08?

How about is 03/03/04 20:10:08 after 03/07/03 14:00:00? Probably the others
above will suffice.
--

(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/>
Aug 24 '08 #1
16 4421
"W. eWatson" <no*******@sbcglobal.netwrites:
Are there some date and time comparison functions that would compare, say,

Is 10/05/05 later than 09/22/02? (or 02/09/22 format, yy/mm/dd)
Is 02/11/07 the same as 02/11/07?

Is 14:05:18 after 22:02:51? (24 hour day is fine)

How about the date after 02/28/04 is 02/29/04, or the date after
09/30/08 is 10/01/08?

How about is 03/03/04 20:10:08 after 03/07/03 14:00:00? Probably the
others above will suffice.
http://docs.python.org/lib/module-datetime.html
Aug 24 '08 #2
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
Aug 25 '08 #3
zu**@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.

--

(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/>
Aug 26 '08 #4
zu**@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
I'm using IDLE for Python 2.4, and put pfydate distribution in
C:\Python24\Lib\site-packages\pfydate, as required by the
How to install pyfdate.

Save pyfdate.py into your PythonNN/Lib/site-packages directory.
I copied it into C:\Python24\Lib\site-packages\pfydate

Execution in IDLE produced:
---------------------------------
Traceback (most recent call last):
File
"C:\Sandia_Meteors\Improved_Sentinel\Sentinel_Play ground\date_example.py",
line 1, in ?
from pyfdate import *
ImportError: No module named pyfdate
---------------------------------
Looking in the Path Browser, I don't see pyfdate. I see PIL package and
scipy package.

--

(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/>
Aug 27 '08 #5
On Aug 27, 10:21 am, "W. eWatson" <notval...@sbcglobal.netwrote:
>
I'm using IDLE for Python 2.4, and put pfydate distribution in
C:\Python24\Lib\site-packages\pfydate, as required by the
How to install pyfdate.

Save pyfdate.py into your PythonNN/Lib/site-packages directory.
I copied it into C:\Python24\Lib\site-packages\pfydate
If that means that you ended up with
C:\Python24\Lib\site-packages\pfydate\pyfdate.py
then you have *not* followed the instructions "Save pyfdate.py into
You need to end up with
C:\Python24\Lib\site-packages\pyfdate.py

If in doubt, get to a command prompt and type
dir C:\Python24\Lib\site-packages\pfydate*
and tell us what you see.
>
Execution in IDLE produced:
---------------------------------
Traceback (most recent call last):
File
"C:\Sandia_Meteors\Improved_Sentinel\Sentinel_Play ground\date_example.py",
line 1, in ?
from pyfdate import *
ImportError: No module named pyfdate
---------------------------------
Looking in the Path Browser, I don't see pyfdate. I see PIL package and
scipy package.
Aug 27 '08 #6
John Machin wrote:
On Aug 27, 10:21 am, "W. eWatson" <notval...@sbcglobal.netwrote:
>I'm using IDLE for Python 2.4, and put pfydate distribution in
C:\Python24\Lib\site-packages\pfydate, as required by the
How to install pyfdate.

Save pyfdate.py into your PythonNN/Lib/site-packages directory.
I copied it into C:\Python24\Lib\site-packages\pfydate

If that means that you ended up with
C:\Python24\Lib\site-packages\pfydate\pyfdate.py
then you have *not* followed the instructions "Save pyfdate.py into
You need to end up with
C:\Python24\Lib\site-packages\pyfdate.py
None of the folders in C:\Python24\Lib\site-packages\ have py as a suffix
(as seen either by the IDLE path browser or XP). My folder is exactly
C:\Python24\Lib\site-packages\pfydate in XP and it contains about 12 py files.
There are exactly three folders under
C:\Python24\Lib\site-packages\ according to the IDLE path browser. This does
not agree with XP, which has:
Numeric
pfydate
scipy
numpy
PIL
>
If in doubt, get to a command prompt and type
dir C:\Python24\Lib\site-packages\pfydate*
and tell us what you see.
>Execution in IDLE produced:
---------------------------------
Traceback (most recent call last):
File
"C:\Sandia_Meteors\Improved_Sentinel\Sentinel_Pla yground\date_example.py",
line 1, in ?
from pyfdate import *
ImportError: No module named pyfdate
---------------------------------
Looking in the Path Browser, I don't see pyfdate. I see PIL package and
scipy package.

--

(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/>
Aug 27 '08 #7
On Aug 27, 11:24*am, "W. eWatson" <notval...@sbcglobal.netwrote:
John Machin wrote:
On Aug 27, 10:21 am, "W. eWatson" <notval...@sbcglobal.netwrote:
I'm using IDLE for Python 2.4, and put pfydate distribution in
C:\Python24\Lib\site-packages\pfydate, as required by the
How to install pyfdate.
* * *Save pyfdate.py into your PythonNN/Lib/site-packages directory.
I copied it into C:\Python24\Lib\site-packages\pfydate
If that means that you ended up with
* *C:\Python24\Lib\site-packages\pfydate\pyfdate.py
then you have *not* followed the instructions "Save pyfdate.py into
You need to end up with
* *C:\Python24\Lib\site-packages\pyfdate.py

None of the folders in C:\Python24\Lib\site-packages\ have py as a suffix
(as seen either by the IDLE path browser or XP). My folder is exactly
C:\Python24\Lib\site-packages\pfydate in XP and it contains about 12 py files.
There are exactly three folders under
C:\Python24\Lib\site-packages\ according to the IDLE path browser. This does
not agree with XP, which has:
Numeric
pfydate
scipy
numpy
PIL
(1) "pfydate" != "pyfdate"
(2) The instructions say to put pyfdate.py [that's *ONE* file, not 12
files] in the ..../site-packages folder, *not* a sub-folder

Aug 27 '08 #8
John Machin wrote:
On Aug 27, 11:24 am, "W. eWatson" <notval...@sbcglobal.netwrote:
>John Machin wrote:
>>On Aug 27, 10:21 am, "W. eWatson" <notval...@sbcglobal.netwrote:
I'm using IDLE for Python 2.4, and put pfydate distribution in
C:\Python24\Lib\site-packages\pfydate, as required by the
How to install pyfdate.
Save pyfdate.py into your PythonNN/Lib/site-packages directory.
I copied it into C:\Python24\Lib\site-packages\pfydate
If that means that you ended up with
C:\Python24\Lib\site-packages\pfydate\pyfdate.py
then you have *not* followed the instructions "Save pyfdate.py into
You need to end up with
C:\Python24\Lib\site-packages\pyfdate.py
None of the folders in C:\Python24\Lib\site-packages\ have py as a suffix
(as seen either by the IDLE path browser or XP). My folder is exactly
C:\Python24\Lib\site-packages\pfydate in XP and it contains about 12 py files.
There are exactly three folders under
C:\Python24\Lib\site-packages\ according to the IDLE path browser. This does
not agree with XP, which has:
Numeric
pfydate
scipy
numpy
PIL

(1) "pfydate" != "pyfdate"
typo
(2) The instructions say to put pyfdate.py [that's *ONE* file, not 12
files] in the ..../site-packages folder, *not* a sub-folder
Got it. Ah, I see upon closer inspection the other files are just
international versions. Thanks. It works.

--

(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/>
Aug 27 '08 #9
I just tried the following code, and got an unexpected result.

from pyfdate import *
t = Time()

ts = Time(2008, 8, 29,15,20,7)
tnew = ts.plus(months=6)
print "new date: ", tnew

Result:
new date: 2009-02-28 15:20:07

I believe that should be April 1, 2009. If I use months = 1 and day =31, I
get Sept. 30, 2008 and not Oct. 1, 2008. Is there a way to get around this?

--
W. Watson
(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

Aug 29 '08 #10
On Aug 30, 2:32 am, "W. eWatson" <notval...@sbcglobal.netwrote:
I just tried the following code, and got an unexpected result.

from pyfdate import *
t = Time()

ts = Time(2008, 8, 29,15,20,7)
tnew = ts.plus(months=6)
print "new date: ", tnew

Result:
new date: 2009-02-28 15:20:07

I believe that should be April 1, 2009.
Presuming that we are talking about the Gregorian calendar, and not
one of your own invention, you are (one trusts) alone in that belief.
There are SEVEN whole months and a bit between August 29, 2008 and
April 1, 2009. Count the months: Sep, Oct, Nov, Dec, Jan, Feb, Mar.
If I use months = 1 and day =31, I
get Sept. 30, 2008 and not Oct. 1, 2008. Is there a way to get around this?
Because the number of days in a month is not constant, adding a number
of months to a date is capable of more than one interpretation. Most
folk are happy with adding the months on and then ensuring that the
day is not later than the last day of the resultant (year, month)
combination -- this is what the pyfdate routine appears to be doing.
However there are some interesting ideas floating around e.g. IIRC an
eminent personage once asserted in this newsgroup that adding 1 month
to 31 Jan in a non-leap year should produce 3 Mar.

There is also the general question with date intervals of whether the
first day is included in the calculation or not. E.g. work on Monday,
Tuesday, Wednesday: that's 3 days service. Put money into the bank on
Monday, withdraw it on Wednesday: that's likely to attract 2 days
interest.

One needs to understand exactly what calculation is required, and
exactly what calculation is provided by the software that is proposed
to be used.

HTH,

John
Aug 29 '08 #11
John Machin wrote:
On Aug 30, 2:32 am, "W. eWatson" <notval...@sbcglobal.netwrote:
>I just tried the following code, and got an unexpected result.

from pyfdate import *
t = Time()

ts = Time(2008, 8, 29,15,20,7)
tnew = ts.plus(months=6)
print "new date: ", tnew

Result:
new date: 2009-02-28 15:20:07

I believe that should be April 1, 2009.

Presuming that we are talking about the Gregorian calendar, and not
one of your own invention, you are (one trusts) alone in that belief.
There are SEVEN whole months and a bit between August 29, 2008 and
April 1, 2009. Count the months: Sep, Oct, Nov, Dec, Jan, Feb, Mar.
>If I use months = 1 and day =31, I
get Sept. 30, 2008 and not Oct. 1, 2008. Is there a way to get around this?

Because the number of days in a month is not constant, adding a number
of months to a date is capable of more than one interpretation. Most
folk are happy with adding the months on and then ensuring that the
day is not later than the last day of the resultant (year, month)
combination -- this is what the pyfdate routine appears to be doing.
However there are some interesting ideas floating around e.g. IIRC an
eminent personage once asserted in this newsgroup that adding 1 month
to 31 Jan in a non-leap year should produce 3 Mar.

There is also the general question with date intervals of whether the
first day is included in the calculation or not. E.g. work on Monday,
Tuesday, Wednesday: that's 3 days service. Put money into the bank on
Monday, withdraw it on Wednesday: that's likely to attract 2 days
interest.

One needs to understand exactly what calculation is required, and
exactly what calculation is provided by the software that is proposed
to be used.

HTH,

John
What I'm trying to do is adjust date-time stamped file names for date and
time errors. The software program collects through a period that roughly
coincides with night hours every day and according to the OS clock. It
sometimes happens that a user sets the clock to the wrong day or hour,
possibly both. Possibly even the month or year. I'm trying to allow a user
the opportunity to repair the problem. (Date-time stamp part of the name is
yyyymmdd_hhmmss.) Correcting the date needs to be done easily and
accurately. For example, if on August 25, he mistakenly sets the date to
July 25, and discovers this problem on the real Oct. 5, he should be able to
shift all dates from July 25 through Sept. 5 to Aug. 25 through early Oct.,
allowing for day oddities in a month during the period. (I hope I got those
dates right; otherwise, I think you get the idea. In other words, he needs
to shift about 40 days of data to the correct dates.) Or:

True calendar period: August 25 to Oct. 5
Recorded calendar period: July 25 to Sept. 5 (roughly 5)

A second function is to correct the time stamp for drift in the clock. For
this, I'm expecting the user knows the daily drift, +/-, in seconds of the
clock. When he decides, for example, that he's let the clock drift for more
than, say, 120 seconds, he may want to adjust the time stamp for all files
collected since the last time he set the clock properly. About the best
anyone can hope for is that the data is accurate to within 4 to 5 seconds,
so over periods of say a month between adjustments this should be OK. The
computers used do not have time data other than that provided by the h/w
clock on the computer. This method is not meant to be a cure all, just to
get the time stamp within a reasonable value. Personally, I reset the time
about every 2-3 weeks. Problems that arise here are associated with working
near midnight. Again, it's possible to set some time or date component
incorrectly each time one needs to get drift under control.

The OSes involved can be Win XP, Win 2000, or even older Win OSes, varieties
of Apple and Linux. I don't want to go below the level of the simple h/w
clock a typical user might have access to through the OS s/w user interface.
However, I do not need to get into OS details to solve the above problems.

There are of course times when a mistaken setting is caught early, so the
adjustment becomes easy. Suppose the day is taken as May 3 on May 5, and two
days later the mistake is noticed. Changing the date for these files is
pretty easy (with the program).

Well, back to the drawing board for awhile to see how this plays against
pyfdate.

--
W. Watson
(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

Aug 30 '08 #12
On Aug 30, 10:41 am, "W. eWatson" <notval...@sbcglobal.netwrote:
What I'm trying to do is adjust date-time stamped file names for date and
time errors. The software program collects through a period that roughly
coincides with night hours every day and according to the OS clock. It
sometimes happens that a user sets the clock to the wrong day or hour,
possibly both. Possibly even the month or year. I'm trying to allow a user
the opportunity to repair the problem. (Date-time stamp part of the name is
yyyymmdd_hhmmss.) Correcting the date needs to be done easily and
accurately. For example, if on August 25, he mistakenly sets the date to
July 25, and discovers this problem on the real Oct. 5, he should be able to
shift all dates from July 25 through Sept. 5 to Aug. 25 through early Oct.,
allowing for day oddities in a month during the period. (I hope I got those
dates right; otherwise, I think you get the idea. In other words, he needs
to shift about 40 days of data to the correct dates.)
.... all of which is absolutely nothing to do with your surprise at the
result of whatever.plus(months=6).

So for some period from recorded date X to recorded date Y, the
recorded dates of out of kilter by D days. X = Jul 25 2008, Y Sep 5
2008, and D is 31 (days from Jul 25 to Aug 25). All you have to do is
(pseudocode):

if X <= recorded_date <= Y:
new_recorded_date = recorded_date.plus(days=D)

HTH,
John

Aug 30 '08 #13
John Machin wrote:
On Aug 30, 10:41 am, "W. eWatson" <notval...@sbcglobal.netwrote:
>What I'm trying to do is adjust date-time stamped file names for date and
time errors. The software program collects through a period that roughly
coincides with night hours every day and according to the OS clock. It
sometimes happens that a user sets the clock to the wrong day or hour,
possibly both. Possibly even the month or year. I'm trying to allow a user
the opportunity to repair the problem. (Date-time stamp part of the name is
yyyymmdd_hhmmss.) Correcting the date needs to be done easily and
accurately. For example, if on August 25, he mistakenly sets the date to
July 25, and discovers this problem on the real Oct. 5, he should be able to
shift all dates from July 25 through Sept. 5 to Aug. 25 through early Oct.,
allowing for day oddities in a month during the period. (I hope I got those
dates right; otherwise, I think you get the idea. In other words, he needs
to shift about 40 days of data to the correct dates.)

... all of which is absolutely nothing to do with your surprise at the
result of whatever.plus(months=6).
Really? It opened new insights for me. The example above is not the only
correction I need to deal with. Further, the author is likely to soon
clarify some of the date rules in the tutorial that were not obvious or
mentioned there.
>
So for some period from recorded date X to recorded date Y, the
recorded dates of out of kilter by D days. X = Jul 25 2008, Y Sep 5
2008, and D is 31 (days from Jul 25 to Aug 25). All you have to do is
(pseudocode):

if X <= recorded_date <= Y:
new_recorded_date = recorded_date.plus(days=D)

HTH,
John

--
W. Watson
(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

Aug 30 '08 #14
W. eWatson wrote:
John Machin wrote:
>On Aug 30, 10:41 am, "W. eWatson" <notval...@sbcglobal.netwrote:
>>What I'm trying to do is adjust date-time stamped file names for date
and
time errors. The software program collects through a period that roughly
coincides with night hours every day and according to the OS clock. It
sometimes happens that a user sets the clock to the wrong day or hour,
possibly both. Possibly even the month or year. I'm trying to allow a
user
the opportunity to repair the problem. (Date-time stamp part of the
name is
yyyymmdd_hhmmss.) Correcting the date needs to be done easily and
accurately. For example, if on August 25, he mistakenly sets the date to
July 25, and discovers this problem on the real Oct. 5, he should be
able to
shift all dates from July 25 through Sept. 5 to Aug. 25 through early
Oct.,
allowing for day oddities in a month during the period. (I hope I got
those
dates right; otherwise, I think you get the idea. In other words, he
needs
to shift about 40 days of data to the correct dates.)

... all of which is absolutely nothing to do with your surprise at the
result of whatever.plus(months=6).
Really? It opened new insights for me. The example above is not the only
correction I need to deal with. Further, the author is likely to soon
clarify some of the date rules in the tutorial that were not obvious or
mentioned there.
>>
So for some period from recorded date X to recorded date Y, the
recorded dates of out of kilter by D days. X = Jul 25 2008, Y Sep 5
2008, and D is 31 (days from Jul 25 to Aug 25). All you have to do is
(pseudocode):

if X <= recorded_date <= Y:
new_recorded_date = recorded_date.plus(days=D)

HTH,
John

Strange how my post got hooked into this side spur. I'll re-post.

--
W. Watson
(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

Aug 30 '08 #15
John Machin wrote:
On Aug 30, 10:41 am, "W. eWatson" <notval...@sbcglobal.netwrote:
>What I'm trying to do is adjust date-time stamped file names for date and
time errors. The software program collects through a period that roughly
coincides with night hours every day and according to the OS clock. It
sometimes happens that a user sets the clock to the wrong day or hour,
possibly both. Possibly even the month or year. I'm trying to allow a user
the opportunity to repair the problem. (Date-time stamp part of the name is
yyyymmdd_hhmmss.) Correcting the date needs to be done easily and
accurately. For example, if on August 25, he mistakenly sets the date to
July 25, and discovers this problem on the real Oct. 5, he should be able to
shift all dates from July 25 through Sept. 5 to Aug. 25 through early Oct.,
allowing for day oddities in a month during the period. (I hope I got those
dates right; otherwise, I think you get the idea. In other words, he needs
to shift about 40 days of data to the correct dates.)

... all of which is absolutely nothing to do with your surprise at the
result of whatever.plus(months=6).
Really? It opened new insights for me. The example above is not the only
correction I need to deal with. Further, the author is likely to soon
clarify some of the date rules in the tutorial that were not obvious nor
mentioned there.
>
So for some period from recorded date X to recorded date Y, the
recorded dates of out of kilter by D days. X = Jul 25 2008, Y Sep 5
2008, and D is 31 (days from Jul 25 to Aug 25). All you have to do is
(pseudocode):

if X <= recorded_date <= Y:
new_recorded_date = recorded_date.plus(days=D)

HTH,
John

--
W. Watson
(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

Aug 30 '08 #16
The author has updated the Tutorial and added a flex method.

Aug 30 '08 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

### Similar topics

 1 by: colinhumber | last post by: I have a datetime variable coming from my ASP.NET application that has a time portion. I give my users the option to perform an equals, greater than, less than, or between comparison. The trouble... 1 by: sylvian stone | last post by: Hi, I've used standard date functions in the past, but need to create something a little different, as I am working on an investment calculator. What I need to do is validate two dates, and... 3 by: usenet | last post by: I have inherited a table where date information was saved from PHP as a VARCHAR. (Sigh.) This means that the so-called date fields look like this : August 1, 2005, 9:09 am EDT October 13, 2004,... 3 by: andrew | last post by: Hi: I am already using TreeMap to massage records in my export file such that each record has a unique key combination ( LastName + FirstName + Member Key) . Thus I am sorting the records by... 4 by: Dim | last post by: I found that C# has some buggy ways to process string across methods. I have a class with on global string var and a method where i add / remove from this string Consider it a buffer... with some... 37 by: spam.noam | last post by: Hello, Guido has decided, in python-dev, that in Py3K the id-based order comparisons will be dropped. This means that, for example, "{} < " will raise a TypeError instead of the current... 7 by: mr.nimz | last post by: hello, this is antenio. recently i've come to a problem. i got a way through it, somehow, still it left me in a curious state, so i'm posting it here, if i can get an answer from some techy, ... 6 by: Luvin lunch | last post by: Hi, I'm new to access and am very wary of dates as I have limited experience in their manipulation and I know if they're not done properly things can turn ugly quickly. I would like to use a... 0 by: Hendrik van Rooyen | last post by: John Machin