RE: Fun with date calculations in VFP
I owe you a Scotch next time you're in the area. -- rk -Original Message- From: ProfoxTech On Behalf Of Ted Roche Sent: Tuesday, May 08, 2018 5:15 PM To: profoxt...@leafe.com Subject: Re: Fun with date calculations in VFP Did I mention I like date math? Brain-twisting stuff. On Tue, May 8, 2018 at 5:14 PM, Ted Roche wrote: > How about: > > FUNCTION olddate(thedate, offset) > * parameters: > * the date: the source date > * offset number of years offset, positive or negative > * returns: the nearest date that is the same day of week as the source date > > LOCAL thediff, theoffset > thediff = DOW(thedate) - DOW(GOMONTH(thedate, offset*12)) > theoffset = IIF(ABS(thediff)>3, 7-SIGN(thediff)*(thediff), thediff) > RETURN GOMONTH(thedate, offset*12)+theoffset > > ABS() only picks up the high end of the date difference, 4,5,6 > SIGN() toggles whether you add or subtract the difference (minus a > minus is a plus) > > > On Tue, May 8, 2018 at 5:03 PM, Ted Roche wrote: >> An ICASE might do it. >> >> Basically the idea is get the day number (DOW) of the current date, >> like 2 for Tuesday if SET FDOW is 1 ("the first day of the week is >> Monday") >> >> Then create a new date with GOMONTH() and get the day number of that, >> some number 1 through 7. So if the new date is a five, I want to go >> back 3 to get to 2. Similarly, if it's a 6, I want to go forward 3 to >> get to the next, closest 2. >> >> So, you want to find the nearest matching day number: they're either >> the same day, so zero offset, or the matching day number are 1,2,3 >> days earlier or later. >> >> so you take the difference between the original date and the new date. >> if the absolute difference is 3 or less, that's your offset and you >> use that to move the new date to the matching day number. >> >> If the difference is -4, -5, -6 or 4, 5, 6 days, you need to look to >> the next/previous weeks' matching day number, hence the magic 7 >> number. >> >> >> On Tue, May 8, 2018 at 3:39 PM, Richard Kaye wrote: >>> Or an ICASE? (I haven't quite wrapped my head around what you're doing >>> there but it seems like there are 3 states?) >>> >>> m.theOffset=ICASE(theDiff>3, 7-m.theDiff,theDiff<-3, 7+m.theDiff, m.theDiff) >>> >>> -- >>> >>> rk >>> >>> -Original Message- >>> From: ProfoxTech On Behalf Of Ted Roche >>> Sent: Tuesday, May 08, 2018 3:25 PM >>> To: profoxt...@leafe.com >>> Subject: Re: Fun with date calculations in VFP >>> >>> GOMONTH() just moves back to 2/28 on years that don't have a 2/29, so >>> your olddate({^2016-02-29},-2) gives you the previous Tuesday, >>> 2/24/2014. >>> >>> Hmmm. That's an OBO. It goes back 4 instead of forward 3. I think the >>> nearest date ought to be 2014-03-03 >>> >>> Ah, if thediff = -4, it remains -4. That's a bug. Add the second line >>> below after the first: >>> >>> m.theOffset=IIF(theDiff>3, 7-m.theDiff, m.theDiff) >>> m.theOffset=IIF(theDiff<-3, 7+m.theDiff, m.theDiff) >>> >>> I know there's a better algorithm, likely involving MOD() or CEILING() >>> or FLOOR() but it's escaping me at the moment. >>> >>> There's 49 combinations of original date = (1,2,3,4,5,6,7) and >>> resultant date = (1,2,3,4,5,6,7) and the offset should come out as >>> {-3,-2,-1,0,1,2,3} , but I'm drawing a blank. Anyone? Beuller? >>> >>> >>> >>> On Tue, May 8, 2018 at 2:15 PM, Richard Kaye wrote: Ted's solution works just fine. What I didn't test yet is using leap day itself as the starting point. Hmmm. ** * Program: datestuff3.prg * Date: 05/08/2018 11:09 AM * VFP Version: Visual FoxPro 09.00..7423 for Windows *Notes: ** ACTIVATE SCREEN CLEAR ? [Today: ]+CHR(9)+CHR(9) ?? DATE() ?? CHR(9)+CDOW(DATE()) ? [Same day last year: ] ?? olddate(DATE(),-1) ?? CHR(9)+CDOW(olddate(DATE(),-1)) ? [Same day 2 years ago: ] ?? olddate(DATE(),-2) ?? CHR(9)+CDOW(olddate(DATE(),-2)) ? [Same day 3 years ago: ] ?? olddate(DATE(),-3) ?? CHR(9)+CDOW(olddate(DATE(),-3)) ? [Same day 10 years ago: ] ?? olddate(DATE(),-10) ?? [ ]+CDOW(olddate(DATE(),-10)) ? [Yesterday: ]+CHR(9) ?? DATE()-1 ?? CHR(9)+CDOW(DATE()-1) ? [Same day last year: ] ?? olddate(DATE()-1,-1) ?? CHR(9)+CDOW(olddate(DATE()-1,-1)) ? [Same day 2 years ago: ] ?? olddate(DATE()-1,-2) ?? CHR(9)+CDOW(olddate(DATE()-1,-2)) ? [Same day 3 years ago: ] ?? olddate(DATE()-1,-3) ?? CHR(9)+CDOW(olddate(DATE()-1,-3)) ? [Same day 10 years ago: ] ?? olddate(DATE()-1,-10) ?? [ ]+CDOW(olddate(DATE()-1,-10)) ? [Tomorrow: ]+CHR(9) ?? DATE()+1 ?? CHR(9)+CDOW(DATE()+1) ? [Same day last year: ] ?? olddate(DATE()+1,-1) ?? CHR(9)+CDOW(olddate(DATE()+1,-1)) ? [Same day 2 years ago: ] ?? olddate(DATE()+1,-2) ?? CHR(9)+CDOW(olddate(DATE
Re: Fun with date calculations in VFP
Did I mention I like date math? Brain-twisting stuff. On Tue, May 8, 2018 at 5:14 PM, Ted Roche wrote: > How about: > > FUNCTION olddate(thedate, offset) > * parameters: > * the date: the source date > * offset number of years offset, positive or negative > * returns: the nearest date that is the same day of week as the source date > > LOCAL thediff, theoffset > thediff = DOW(thedate) - DOW(GOMONTH(thedate, offset*12)) > theoffset = IIF(ABS(thediff)>3, 7-SIGN(thediff)*(thediff), thediff) > RETURN GOMONTH(thedate, offset*12)+theoffset > > ABS() only picks up the high end of the date difference, 4,5,6 > SIGN() toggles whether you add or subtract the difference (minus a > minus is a plus) > > > On Tue, May 8, 2018 at 5:03 PM, Ted Roche wrote: >> An ICASE might do it. >> >> Basically the idea is get the day number (DOW) of the current date, >> like 2 for Tuesday if SET FDOW is 1 ("the first day of the week is >> Monday") >> >> Then create a new date with GOMONTH() and get the day number of that, >> some number 1 through 7. So if the new date is a five, I want to go >> back 3 to get to 2. Similarly, if it's a 6, I want to go forward 3 to >> get to the next, closest 2. >> >> So, you want to find the nearest matching day number: they're either >> the same day, so zero offset, or the matching day number are 1,2,3 >> days earlier or later. >> >> so you take the difference between the original date and the new date. >> if the absolute difference is 3 or less, that's your offset and you >> use that to move the new date to the matching day number. >> >> If the difference is -4, -5, -6 or 4, 5, 6 days, you need to look to >> the next/previous weeks' matching day number, hence the magic 7 >> number. >> >> >> On Tue, May 8, 2018 at 3:39 PM, Richard Kaye wrote: >>> Or an ICASE? (I haven't quite wrapped my head around what you're doing >>> there but it seems like there are 3 states?) >>> >>> m.theOffset=ICASE(theDiff>3, 7-m.theDiff,theDiff<-3, 7+m.theDiff, m.theDiff) >>> >>> -- >>> >>> rk >>> >>> -Original Message- >>> From: ProfoxTech On Behalf Of Ted Roche >>> Sent: Tuesday, May 08, 2018 3:25 PM >>> To: profoxt...@leafe.com >>> Subject: Re: Fun with date calculations in VFP >>> >>> GOMONTH() just moves back to 2/28 on years that don't have a 2/29, so >>> your olddate({^2016-02-29},-2) gives you the previous Tuesday, >>> 2/24/2014. >>> >>> Hmmm. That's an OBO. It goes back 4 instead of forward 3. I think the >>> nearest date ought to be 2014-03-03 >>> >>> Ah, if thediff = -4, it remains -4. That's a bug. Add the second line >>> below after the first: >>> >>> m.theOffset=IIF(theDiff>3, 7-m.theDiff, m.theDiff) >>> m.theOffset=IIF(theDiff<-3, 7+m.theDiff, m.theDiff) >>> >>> I know there's a better algorithm, likely involving MOD() or CEILING() >>> or FLOOR() but it's escaping me at the moment. >>> >>> There's 49 combinations of original date = (1,2,3,4,5,6,7) and >>> resultant date = (1,2,3,4,5,6,7) and the offset should come out as >>> {-3,-2,-1,0,1,2,3} , but I'm drawing a blank. Anyone? Beuller? >>> >>> >>> >>> On Tue, May 8, 2018 at 2:15 PM, Richard Kaye wrote: Ted's solution works just fine. What I didn't test yet is using leap day itself as the starting point. Hmmm. ** * Program: datestuff3.prg * Date: 05/08/2018 11:09 AM * VFP Version: Visual FoxPro 09.00..7423 for Windows *Notes: ** ACTIVATE SCREEN CLEAR ? [Today: ]+CHR(9)+CHR(9) ?? DATE() ?? CHR(9)+CDOW(DATE()) ? [Same day last year: ] ?? olddate(DATE(),-1) ?? CHR(9)+CDOW(olddate(DATE(),-1)) ? [Same day 2 years ago: ] ?? olddate(DATE(),-2) ?? CHR(9)+CDOW(olddate(DATE(),-2)) ? [Same day 3 years ago: ] ?? olddate(DATE(),-3) ?? CHR(9)+CDOW(olddate(DATE(),-3)) ? [Same day 10 years ago: ] ?? olddate(DATE(),-10) ?? [ ]+CDOW(olddate(DATE(),-10)) ? [Yesterday: ]+CHR(9) ?? DATE()-1 ?? CHR(9)+CDOW(DATE()-1) ? [Same day last year: ] ?? olddate(DATE()-1,-1) ?? CHR(9)+CDOW(olddate(DATE()-1,-1)) ? [Same day 2 years ago: ] ?? olddate(DATE()-1,-2) ?? CHR(9)+CDOW(olddate(DATE()-1,-2)) ? [Same day 3 years ago: ] ?? olddate(DATE()-1,-3) ?? CHR(9)+CDOW(olddate(DATE()-1,-3)) ? [Same day 10 years ago: ] ?? olddate(DATE()-1,-10) ?? [ ]+CDOW(olddate(DATE()-1,-10)) ? [Tomorrow: ]+CHR(9) ?? DATE()+1 ?? CHR(9)+CDOW(DATE()+1) ? [Same day last year: ] ?? olddate(DATE()+1,-1) ?? CHR(9)+CDOW(olddate(DATE()+1,-1)) ? [Same day 2 years ago: ] ?? olddate(DATE()+1,-2) ?? CHR(9)+CDOW(olddate(DATE()+1,-2)) ? [Same day 3 years ago: ] ?? olddate(DATE()+1,-3) ?? CHR(9)+CDOW(olddate(DATE()+1,-3)) ? [Same day 10 years ago: ] ?? olddate(DATE()+1,-10) ?? [ ]+CDOW(olddate(DATE()+1,-10)) FUNCTIO
Re: Fun with date calculations in VFP
How about: FUNCTION olddate(thedate, offset) * parameters: * the date: the source date * offset number of years offset, positive or negative * returns: the nearest date that is the same day of week as the source date LOCAL thediff, theoffset thediff = DOW(thedate) - DOW(GOMONTH(thedate, offset*12)) theoffset = IIF(ABS(thediff)>3, 7-SIGN(thediff)*(thediff), thediff) RETURN GOMONTH(thedate, offset*12)+theoffset ABS() only picks up the high end of the date difference, 4,5,6 SIGN() toggles whether you add or subtract the difference (minus a minus is a plus) On Tue, May 8, 2018 at 5:03 PM, Ted Roche wrote: > An ICASE might do it. > > Basically the idea is get the day number (DOW) of the current date, > like 2 for Tuesday if SET FDOW is 1 ("the first day of the week is > Monday") > > Then create a new date with GOMONTH() and get the day number of that, > some number 1 through 7. So if the new date is a five, I want to go > back 3 to get to 2. Similarly, if it's a 6, I want to go forward 3 to > get to the next, closest 2. > > So, you want to find the nearest matching day number: they're either > the same day, so zero offset, or the matching day number are 1,2,3 > days earlier or later. > > so you take the difference between the original date and the new date. > if the absolute difference is 3 or less, that's your offset and you > use that to move the new date to the matching day number. > > If the difference is -4, -5, -6 or 4, 5, 6 days, you need to look to > the next/previous weeks' matching day number, hence the magic 7 > number. > > > On Tue, May 8, 2018 at 3:39 PM, Richard Kaye wrote: >> Or an ICASE? (I haven't quite wrapped my head around what you're doing there >> but it seems like there are 3 states?) >> >> m.theOffset=ICASE(theDiff>3, 7-m.theDiff,theDiff<-3, 7+m.theDiff, m.theDiff) >> >> -- >> >> rk >> >> -Original Message- >> From: ProfoxTech On Behalf Of Ted Roche >> Sent: Tuesday, May 08, 2018 3:25 PM >> To: profoxt...@leafe.com >> Subject: Re: Fun with date calculations in VFP >> >> GOMONTH() just moves back to 2/28 on years that don't have a 2/29, so >> your olddate({^2016-02-29},-2) gives you the previous Tuesday, >> 2/24/2014. >> >> Hmmm. That's an OBO. It goes back 4 instead of forward 3. I think the >> nearest date ought to be 2014-03-03 >> >> Ah, if thediff = -4, it remains -4. That's a bug. Add the second line >> below after the first: >> >> m.theOffset=IIF(theDiff>3, 7-m.theDiff, m.theDiff) >> m.theOffset=IIF(theDiff<-3, 7+m.theDiff, m.theDiff) >> >> I know there's a better algorithm, likely involving MOD() or CEILING() >> or FLOOR() but it's escaping me at the moment. >> >> There's 49 combinations of original date = (1,2,3,4,5,6,7) and >> resultant date = (1,2,3,4,5,6,7) and the offset should come out as >> {-3,-2,-1,0,1,2,3} , but I'm drawing a blank. Anyone? Beuller? >> >> >> >> On Tue, May 8, 2018 at 2:15 PM, Richard Kaye wrote: >>> Ted's solution works just fine. What I didn't test yet is using leap day >>> itself as the starting point. Hmmm. >>> >>> ** >>> * Program: datestuff3.prg >>> * Date: 05/08/2018 11:09 AM >>> * VFP Version: Visual FoxPro 09.00..7423 for Windows >>> *Notes: >>> ** >>> ACTIVATE SCREEN >>> CLEAR >>> ? [Today: ]+CHR(9)+CHR(9) >>> ?? DATE() >>> ?? CHR(9)+CDOW(DATE()) >>> ? [Same day last year: ] >>> ?? olddate(DATE(),-1) >>> ?? CHR(9)+CDOW(olddate(DATE(),-1)) >>> ? [Same day 2 years ago: ] >>> ?? olddate(DATE(),-2) >>> ?? CHR(9)+CDOW(olddate(DATE(),-2)) >>> ? [Same day 3 years ago: ] >>> ?? olddate(DATE(),-3) >>> ?? CHR(9)+CDOW(olddate(DATE(),-3)) >>> ? [Same day 10 years ago: ] >>> ?? olddate(DATE(),-10) >>> ?? [ ]+CDOW(olddate(DATE(),-10)) >>> ? [Yesterday: ]+CHR(9) >>> ?? DATE()-1 >>> ?? CHR(9)+CDOW(DATE()-1) >>> ? [Same day last year: ] >>> ?? olddate(DATE()-1,-1) >>> ?? CHR(9)+CDOW(olddate(DATE()-1,-1)) >>> ? [Same day 2 years ago: ] >>> ?? olddate(DATE()-1,-2) >>> ?? CHR(9)+CDOW(olddate(DATE()-1,-2)) >>> ? [Same day 3 years ago: ] >>> ?? olddate(DATE()-1,-3) >>> ?? CHR(9)+CDOW(olddate(DATE()-1,-3)) >>> ? [Same day 10 years ago: ] >>> ?? olddate(DATE()-1,-10) >>> ?? [ ]+CDOW(olddate(DATE()-1,-10)) >>> ? [Tomorrow: ]+CHR(9) >>> ?? DATE()+1 >>> ?? CHR(9)+CDOW(DATE()+1) >>> ? [Same day last year: ] >>> ?? olddate(DATE()+1,-1) >>> ?? CHR(9)+CDOW(olddate(DATE()+1,-1)) >>> ? [Same day 2 years ago: ] >>> ?? olddate(DATE()+1,-2) >>> ?? CHR(9)+CDOW(olddate(DATE()+1,-2)) >>> ? [Same day 3 years ago: ] >>> ?? olddate(DATE()+1,-3) >>> ?? CHR(9)+CDOW(olddate(DATE()+1,-3)) >>> ? [Same day 10 years ago: ] >>> ?? olddate(DATE()+1,-10) >>> ?? [ ]+CDOW(olddate(DATE()+1,-10)) >>> >>> FUNCTION oldDate(theDate AS Date, offset AS Integer) >>> * compliments of Ted Roche >>> * parameters: thedate: date to start from >>> * offset: number of years offset, positive or negative >>> * returns: nearest date to the offset that falls on the same day of the wee
Re: Fun with date calculations in VFP
An ICASE might do it. Basically the idea is get the day number (DOW) of the current date, like 2 for Tuesday if SET FDOW is 1 ("the first day of the week is Monday") Then create a new date with GOMONTH() and get the day number of that, some number 1 through 7. So if the new date is a five, I want to go back 3 to get to 2. Similarly, if it's a 6, I want to go forward 3 to get to the next, closest 2. So, you want to find the nearest matching day number: they're either the same day, so zero offset, or the matching day number are 1,2,3 days earlier or later. so you take the difference between the original date and the new date. if the absolute difference is 3 or less, that's your offset and you use that to move the new date to the matching day number. If the difference is -4, -5, -6 or 4, 5, 6 days, you need to look to the next/previous weeks' matching day number, hence the magic 7 number. On Tue, May 8, 2018 at 3:39 PM, Richard Kaye wrote: > Or an ICASE? (I haven't quite wrapped my head around what you're doing there > but it seems like there are 3 states?) > > m.theOffset=ICASE(theDiff>3, 7-m.theDiff,theDiff<-3, 7+m.theDiff, m.theDiff) > > -- > > rk > > -Original Message- > From: ProfoxTech On Behalf Of Ted Roche > Sent: Tuesday, May 08, 2018 3:25 PM > To: profoxt...@leafe.com > Subject: Re: Fun with date calculations in VFP > > GOMONTH() just moves back to 2/28 on years that don't have a 2/29, so > your olddate({^2016-02-29},-2) gives you the previous Tuesday, > 2/24/2014. > > Hmmm. That's an OBO. It goes back 4 instead of forward 3. I think the > nearest date ought to be 2014-03-03 > > Ah, if thediff = -4, it remains -4. That's a bug. Add the second line > below after the first: > > m.theOffset=IIF(theDiff>3, 7-m.theDiff, m.theDiff) > m.theOffset=IIF(theDiff<-3, 7+m.theDiff, m.theDiff) > > I know there's a better algorithm, likely involving MOD() or CEILING() > or FLOOR() but it's escaping me at the moment. > > There's 49 combinations of original date = (1,2,3,4,5,6,7) and > resultant date = (1,2,3,4,5,6,7) and the offset should come out as > {-3,-2,-1,0,1,2,3} , but I'm drawing a blank. Anyone? Beuller? > > > > On Tue, May 8, 2018 at 2:15 PM, Richard Kaye wrote: >> Ted's solution works just fine. What I didn't test yet is using leap day >> itself as the starting point. Hmmm. >> >> ** >> * Program: datestuff3.prg >> * Date: 05/08/2018 11:09 AM >> * VFP Version: Visual FoxPro 09.00..7423 for Windows >> *Notes: >> ** >> ACTIVATE SCREEN >> CLEAR >> ? [Today: ]+CHR(9)+CHR(9) >> ?? DATE() >> ?? CHR(9)+CDOW(DATE()) >> ? [Same day last year: ] >> ?? olddate(DATE(),-1) >> ?? CHR(9)+CDOW(olddate(DATE(),-1)) >> ? [Same day 2 years ago: ] >> ?? olddate(DATE(),-2) >> ?? CHR(9)+CDOW(olddate(DATE(),-2)) >> ? [Same day 3 years ago: ] >> ?? olddate(DATE(),-3) >> ?? CHR(9)+CDOW(olddate(DATE(),-3)) >> ? [Same day 10 years ago: ] >> ?? olddate(DATE(),-10) >> ?? [ ]+CDOW(olddate(DATE(),-10)) >> ? [Yesterday: ]+CHR(9) >> ?? DATE()-1 >> ?? CHR(9)+CDOW(DATE()-1) >> ? [Same day last year: ] >> ?? olddate(DATE()-1,-1) >> ?? CHR(9)+CDOW(olddate(DATE()-1,-1)) >> ? [Same day 2 years ago: ] >> ?? olddate(DATE()-1,-2) >> ?? CHR(9)+CDOW(olddate(DATE()-1,-2)) >> ? [Same day 3 years ago: ] >> ?? olddate(DATE()-1,-3) >> ?? CHR(9)+CDOW(olddate(DATE()-1,-3)) >> ? [Same day 10 years ago: ] >> ?? olddate(DATE()-1,-10) >> ?? [ ]+CDOW(olddate(DATE()-1,-10)) >> ? [Tomorrow: ]+CHR(9) >> ?? DATE()+1 >> ?? CHR(9)+CDOW(DATE()+1) >> ? [Same day last year: ] >> ?? olddate(DATE()+1,-1) >> ?? CHR(9)+CDOW(olddate(DATE()+1,-1)) >> ? [Same day 2 years ago: ] >> ?? olddate(DATE()+1,-2) >> ?? CHR(9)+CDOW(olddate(DATE()+1,-2)) >> ? [Same day 3 years ago: ] >> ?? olddate(DATE()+1,-3) >> ?? CHR(9)+CDOW(olddate(DATE()+1,-3)) >> ? [Same day 10 years ago: ] >> ?? olddate(DATE()+1,-10) >> ?? [ ]+CDOW(olddate(DATE()+1,-10)) >> >> FUNCTION oldDate(theDate AS Date, offset AS Integer) >> * compliments of Ted Roche >> * parameters: thedate: date to start from >> * offset: number of years offset, positive or negative >> * returns: nearest date to the offset that falls on the same day of the week >> LOCAL m.theDiff, m.theOffset >> m.theDiff=DOW(m.theDate)-DOW(GOMONTH(m.theDate, m.offset*12)) >> m.theOffset=IIF(theDiff>3, 7-m.theDiff, m.theDiff) >> RETURN GOMONTH(m.theDate, m.offset*12) + m.theOffset >> >> ENDFUNC >> >> -- >> >> rk >> >> -Original Message- >> From: ProfoxTech On Behalf Of Gene Wirchenko >> Sent: Tuesday, May 08, 2018 12:46 PM >> To: profoxt...@leafe.com >> Subject: RE: Fun with date calculations in VFP >> >> At 06:27 2018-05-08, Richard Kaye wrote: >>>The latter. And that was the approach I was just working through. >> >> What about the week every few years that you will be disregarding? >> >> A year has 52 weeks plus one or two days. >> >> [snip] >> >> Sincerely, >> >> Gene Wirchenko >> >> [excessive
RE: Fun with date calculations in VFP
Or an ICASE? (I haven't quite wrapped my head around what you're doing there but it seems like there are 3 states?) m.theOffset=ICASE(theDiff>3, 7-m.theDiff,theDiff<-3, 7+m.theDiff, m.theDiff) -- rk -Original Message- From: ProfoxTech On Behalf Of Ted Roche Sent: Tuesday, May 08, 2018 3:25 PM To: profoxt...@leafe.com Subject: Re: Fun with date calculations in VFP GOMONTH() just moves back to 2/28 on years that don't have a 2/29, so your olddate({^2016-02-29},-2) gives you the previous Tuesday, 2/24/2014. Hmmm. That's an OBO. It goes back 4 instead of forward 3. I think the nearest date ought to be 2014-03-03 Ah, if thediff = -4, it remains -4. That's a bug. Add the second line below after the first: m.theOffset=IIF(theDiff>3, 7-m.theDiff, m.theDiff) m.theOffset=IIF(theDiff<-3, 7+m.theDiff, m.theDiff) I know there's a better algorithm, likely involving MOD() or CEILING() or FLOOR() but it's escaping me at the moment. There's 49 combinations of original date = (1,2,3,4,5,6,7) and resultant date = (1,2,3,4,5,6,7) and the offset should come out as {-3,-2,-1,0,1,2,3} , but I'm drawing a blank. Anyone? Beuller? On Tue, May 8, 2018 at 2:15 PM, Richard Kaye wrote: > Ted's solution works just fine. What I didn't test yet is using leap day > itself as the starting point. Hmmm. > > ** > * Program: datestuff3.prg > * Date: 05/08/2018 11:09 AM > * VFP Version: Visual FoxPro 09.00..7423 for Windows > *Notes: > ** > ACTIVATE SCREEN > CLEAR > ? [Today: ]+CHR(9)+CHR(9) > ?? DATE() > ?? CHR(9)+CDOW(DATE()) > ? [Same day last year: ] > ?? olddate(DATE(),-1) > ?? CHR(9)+CDOW(olddate(DATE(),-1)) > ? [Same day 2 years ago: ] > ?? olddate(DATE(),-2) > ?? CHR(9)+CDOW(olddate(DATE(),-2)) > ? [Same day 3 years ago: ] > ?? olddate(DATE(),-3) > ?? CHR(9)+CDOW(olddate(DATE(),-3)) > ? [Same day 10 years ago: ] > ?? olddate(DATE(),-10) > ?? [ ]+CDOW(olddate(DATE(),-10)) > ? [Yesterday: ]+CHR(9) > ?? DATE()-1 > ?? CHR(9)+CDOW(DATE()-1) > ? [Same day last year: ] > ?? olddate(DATE()-1,-1) > ?? CHR(9)+CDOW(olddate(DATE()-1,-1)) > ? [Same day 2 years ago: ] > ?? olddate(DATE()-1,-2) > ?? CHR(9)+CDOW(olddate(DATE()-1,-2)) > ? [Same day 3 years ago: ] > ?? olddate(DATE()-1,-3) > ?? CHR(9)+CDOW(olddate(DATE()-1,-3)) > ? [Same day 10 years ago: ] > ?? olddate(DATE()-1,-10) > ?? [ ]+CDOW(olddate(DATE()-1,-10)) > ? [Tomorrow: ]+CHR(9) > ?? DATE()+1 > ?? CHR(9)+CDOW(DATE()+1) > ? [Same day last year: ] > ?? olddate(DATE()+1,-1) > ?? CHR(9)+CDOW(olddate(DATE()+1,-1)) > ? [Same day 2 years ago: ] > ?? olddate(DATE()+1,-2) > ?? CHR(9)+CDOW(olddate(DATE()+1,-2)) > ? [Same day 3 years ago: ] > ?? olddate(DATE()+1,-3) > ?? CHR(9)+CDOW(olddate(DATE()+1,-3)) > ? [Same day 10 years ago: ] > ?? olddate(DATE()+1,-10) > ?? [ ]+CDOW(olddate(DATE()+1,-10)) > > FUNCTION oldDate(theDate AS Date, offset AS Integer) > * compliments of Ted Roche > * parameters: thedate: date to start from > * offset: number of years offset, positive or negative > * returns: nearest date to the offset that falls on the same day of the week > LOCAL m.theDiff, m.theOffset > m.theDiff=DOW(m.theDate)-DOW(GOMONTH(m.theDate, m.offset*12)) > m.theOffset=IIF(theDiff>3, 7-m.theDiff, m.theDiff) > RETURN GOMONTH(m.theDate, m.offset*12) + m.theOffset > > ENDFUNC > > -- > > rk > > -Original Message- > From: ProfoxTech On Behalf Of Gene Wirchenko > Sent: Tuesday, May 08, 2018 12:46 PM > To: profoxt...@leafe.com > Subject: RE: Fun with date calculations in VFP > > At 06:27 2018-05-08, Richard Kaye wrote: >>The latter. And that was the approach I was just working through. > > What about the week every few years that you will be disregarding? > > A year has 52 weeks plus one or two days. > > [snip] > > Sincerely, > > Gene Wirchenko > > [excessive quoting removed by server] ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/dm5pr10mb124437cdc99d2ad03ff1e05fd2...@dm5pr10mb1244.namprd10.prod.outlook.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Re: Fun with date calculations in VFP
GOMONTH() just moves back to 2/28 on years that don't have a 2/29, so your olddate({^2016-02-29},-2) gives you the previous Tuesday, 2/24/2014. Hmmm. That's an OBO. It goes back 4 instead of forward 3. I think the nearest date ought to be 2014-03-03 Ah, if thediff = -4, it remains -4. That's a bug. Add the second line below after the first: m.theOffset=IIF(theDiff>3, 7-m.theDiff, m.theDiff) m.theOffset=IIF(theDiff<-3, 7+m.theDiff, m.theDiff) I know there's a better algorithm, likely involving MOD() or CEILING() or FLOOR() but it's escaping me at the moment. There's 49 combinations of original date = (1,2,3,4,5,6,7) and resultant date = (1,2,3,4,5,6,7) and the offset should come out as {-3,-2,-1,0,1,2,3} , but I'm drawing a blank. Anyone? Beuller? On Tue, May 8, 2018 at 2:15 PM, Richard Kaye wrote: > Ted's solution works just fine. What I didn't test yet is using leap day > itself as the starting point. Hmmm. > > ** > * Program: datestuff3.prg > * Date: 05/08/2018 11:09 AM > * VFP Version: Visual FoxPro 09.00..7423 for Windows > *Notes: > ** > ACTIVATE SCREEN > CLEAR > ? [Today: ]+CHR(9)+CHR(9) > ?? DATE() > ?? CHR(9)+CDOW(DATE()) > ? [Same day last year: ] > ?? olddate(DATE(),-1) > ?? CHR(9)+CDOW(olddate(DATE(),-1)) > ? [Same day 2 years ago: ] > ?? olddate(DATE(),-2) > ?? CHR(9)+CDOW(olddate(DATE(),-2)) > ? [Same day 3 years ago: ] > ?? olddate(DATE(),-3) > ?? CHR(9)+CDOW(olddate(DATE(),-3)) > ? [Same day 10 years ago: ] > ?? olddate(DATE(),-10) > ?? [ ]+CDOW(olddate(DATE(),-10)) > ? [Yesterday: ]+CHR(9) > ?? DATE()-1 > ?? CHR(9)+CDOW(DATE()-1) > ? [Same day last year: ] > ?? olddate(DATE()-1,-1) > ?? CHR(9)+CDOW(olddate(DATE()-1,-1)) > ? [Same day 2 years ago: ] > ?? olddate(DATE()-1,-2) > ?? CHR(9)+CDOW(olddate(DATE()-1,-2)) > ? [Same day 3 years ago: ] > ?? olddate(DATE()-1,-3) > ?? CHR(9)+CDOW(olddate(DATE()-1,-3)) > ? [Same day 10 years ago: ] > ?? olddate(DATE()-1,-10) > ?? [ ]+CDOW(olddate(DATE()-1,-10)) > ? [Tomorrow: ]+CHR(9) > ?? DATE()+1 > ?? CHR(9)+CDOW(DATE()+1) > ? [Same day last year: ] > ?? olddate(DATE()+1,-1) > ?? CHR(9)+CDOW(olddate(DATE()+1,-1)) > ? [Same day 2 years ago: ] > ?? olddate(DATE()+1,-2) > ?? CHR(9)+CDOW(olddate(DATE()+1,-2)) > ? [Same day 3 years ago: ] > ?? olddate(DATE()+1,-3) > ?? CHR(9)+CDOW(olddate(DATE()+1,-3)) > ? [Same day 10 years ago: ] > ?? olddate(DATE()+1,-10) > ?? [ ]+CDOW(olddate(DATE()+1,-10)) > > FUNCTION oldDate(theDate AS Date, offset AS Integer) > * compliments of Ted Roche > * parameters: thedate: date to start from > * offset: number of years offset, positive or negative > * returns: nearest date to the offset that falls on the same day of the week > LOCAL m.theDiff, m.theOffset > m.theDiff=DOW(m.theDate)-DOW(GOMONTH(m.theDate, m.offset*12)) > m.theOffset=IIF(theDiff>3, 7-m.theDiff, m.theDiff) > RETURN GOMONTH(m.theDate, m.offset*12) + m.theOffset > > ENDFUNC > > -- > > rk > > -Original Message- > From: ProfoxTech On Behalf Of Gene Wirchenko > Sent: Tuesday, May 08, 2018 12:46 PM > To: profoxt...@leafe.com > Subject: RE: Fun with date calculations in VFP > > At 06:27 2018-05-08, Richard Kaye wrote: >>The latter. And that was the approach I was just working through. > > What about the week every few years that you will be disregarding? > > A year has 52 weeks plus one or two days. > > [snip] > > Sincerely, > > Gene Wirchenko > > [excessive quoting removed by server] ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/CACW6n4uxE3UCFQwf3H_9uznN=p1e_yx63bdrcmbz52yjpx_...@mail.gmail.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
RE: Fun with date calculations in VFP
Ted's solution works just fine. What I didn't test yet is using leap day itself as the starting point. Hmmm. ** * Program: datestuff3.prg * Date: 05/08/2018 11:09 AM * VFP Version: Visual FoxPro 09.00..7423 for Windows *Notes: ** ACTIVATE SCREEN CLEAR ? [Today: ]+CHR(9)+CHR(9) ?? DATE() ?? CHR(9)+CDOW(DATE()) ? [Same day last year: ] ?? olddate(DATE(),-1) ?? CHR(9)+CDOW(olddate(DATE(),-1)) ? [Same day 2 years ago: ] ?? olddate(DATE(),-2) ?? CHR(9)+CDOW(olddate(DATE(),-2)) ? [Same day 3 years ago: ] ?? olddate(DATE(),-3) ?? CHR(9)+CDOW(olddate(DATE(),-3)) ? [Same day 10 years ago: ] ?? olddate(DATE(),-10) ?? [ ]+CDOW(olddate(DATE(),-10)) ? [Yesterday: ]+CHR(9) ?? DATE()-1 ?? CHR(9)+CDOW(DATE()-1) ? [Same day last year: ] ?? olddate(DATE()-1,-1) ?? CHR(9)+CDOW(olddate(DATE()-1,-1)) ? [Same day 2 years ago: ] ?? olddate(DATE()-1,-2) ?? CHR(9)+CDOW(olddate(DATE()-1,-2)) ? [Same day 3 years ago: ] ?? olddate(DATE()-1,-3) ?? CHR(9)+CDOW(olddate(DATE()-1,-3)) ? [Same day 10 years ago: ] ?? olddate(DATE()-1,-10) ?? [ ]+CDOW(olddate(DATE()-1,-10)) ? [Tomorrow: ]+CHR(9) ?? DATE()+1 ?? CHR(9)+CDOW(DATE()+1) ? [Same day last year: ] ?? olddate(DATE()+1,-1) ?? CHR(9)+CDOW(olddate(DATE()+1,-1)) ? [Same day 2 years ago: ] ?? olddate(DATE()+1,-2) ?? CHR(9)+CDOW(olddate(DATE()+1,-2)) ? [Same day 3 years ago: ] ?? olddate(DATE()+1,-3) ?? CHR(9)+CDOW(olddate(DATE()+1,-3)) ? [Same day 10 years ago: ] ?? olddate(DATE()+1,-10) ?? [ ]+CDOW(olddate(DATE()+1,-10)) FUNCTION oldDate(theDate AS Date, offset AS Integer) * compliments of Ted Roche * parameters: thedate: date to start from * offset: number of years offset, positive or negative * returns: nearest date to the offset that falls on the same day of the week LOCAL m.theDiff, m.theOffset m.theDiff=DOW(m.theDate)-DOW(GOMONTH(m.theDate, m.offset*12)) m.theOffset=IIF(theDiff>3, 7-m.theDiff, m.theDiff) RETURN GOMONTH(m.theDate, m.offset*12) + m.theOffset ENDFUNC -- rk -Original Message- From: ProfoxTech On Behalf Of Gene Wirchenko Sent: Tuesday, May 08, 2018 12:46 PM To: profoxt...@leafe.com Subject: RE: Fun with date calculations in VFP At 06:27 2018-05-08, Richard Kaye wrote: >The latter. And that was the approach I was just working through. What about the week every few years that you will be disregarding? A year has 52 weeks plus one or two days. [snip] Sincerely, Gene Wirchenko ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/dm5pr10mb1244761defc7089d74f1fc26d2...@dm5pr10mb1244.namprd10.prod.outlook.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Re: Fun with date calculations in VFP
Rofl Op di 8 mei 2018 16:27 schreef Ted Roche : > On Tue, May 8, 2018 at 11:23 AM, Richard Kaye > wrote: > > Another guy that fixes his typos the 2nd time... π Thanks, Ted! > > :) > > Well, the first version ran great in GMail! The second version I > actually tried running in VFP ;) > [excessive quoting removed by server] ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/CAPqLOBxXA8rr4LbCJjf1xGob+s3xtK+Nw=pkebmdseluvsp...@mail.gmail.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
RE: Fun with date calculations in VFP
At 06:27 2018-05-08, Richard Kaye wrote: The latter. And that was the approach I was just working through. What about the week every few years that you will be disregarding? A year has 52 weeks plus one or two days. [snip] Sincerely, Gene Wirchenko ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/b8c15e5c2d5f9c73d3172ea5817a397f@mtlp85 ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
RE: Fun with date calculations in VFP
The Google knows all, sees all, and has nothing but our best interests at heart. But the Google has no proofreading skills... Or DWIMNWIT π -- rk -Original Message- From: ProfoxTech On Behalf Of Dave Crozier Sent: Tuesday, May 08, 2018 12:00 PM To: profoxt...@leafe.com Subject: RE: Fun with date calculations in VFP Richard, It was the Google Effect ... just like mine!! Dave Crozier Software Development Manager Flexipol Packaging Ltd. -Original Message- From: ProfoxTech On Behalf Of Ted Roche Sent: Tuesday, May 08, 2018 11:28 AM To: profoxt...@leafe.com Subject: Re: Fun with date calculations in VFP On Tue, May 8, 2018 at 11:23 AM, Richard Kaye wrote: > Another guy that fixes his typos the 2nd time... π Thanks, Ted! :) Well, the first version ran great in GMail! The second version I actually tried running in VFP ;) ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/dm5pr10mb12443b4f9ce94f593fa3ec81d2...@dm5pr10mb1244.namprd10.prod.outlook.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
RE: Fun with date calculations in VFP
Richard, It was the Google Effect ... just like mine!! Dave Crozier Software Development Manager Flexipol Packaging Ltd. --- This communication and the information it contains is intended for the person or organisation to whom it is addressed. Its contents are confidential and may be protected in law. If you have received this e-mail in error you must not copy, distribute or take any action in reliance on it. Unauthorised use, copying or disclosure of any of it may be unlawful. If you have received this message in error, please notify us immediately by telephone or email. Flexipol Packaging Ltd. has taken every reasonable precaution to minimise the risk of virus transmission through email and therefore any files sent via e-mail will have been checked for known viruses. However, you are advised to run your own virus check before opening any attachments received as Flexipol Packaging Ltd will not in any event accept any liability whatsoever once an e-mail and/or any attachment is received. It is the responsibility of the recipient to ensure that they have adequate virus protection. Flexipol Packaging Ltd. Unit 14 Bentwood Road Carrs Industrial Estate Haslingden Rossendale Lancashire BB4 5HH Tel:01706-222792 Fax: 01706-224683 www.Flexipol.co.uk --- Terms & Conditions: Notwithstanding delivery and the passing of risk in the goods, the property in the goods shall not pass to the buyer until the seller Flexipol Packaging Ltd. ("The Company") has received in cash or cleared funds payment in full of the price of the goods and all other goods agreed to be sold by the seller to the buyer for which payment is then due. Until such time as the property in the goods passes to the buyer, the buyer shall hold the goods as the seller's fiduciary agent and bailee and keep the goods separate from those of the buyer and third parties and properly stored protected and insured and identified as the seller's property but shall be entitled to resell or use the goods in the ordinary course of its business. Until such time as the property in the goods passes to the buyer the seller shall be entitled at any time -Original Message- From: ProFox On Behalf Of Richard Kaye Sent: 08 May 2018 16:53 To: profox@leafe.com Subject: RE: Fun with date calculations in VFP lol -- rk -Original Message- From: ProfoxTech On Behalf Of Ted Roche Sent: Tuesday, May 08, 2018 11:28 AM To: profoxt...@leafe.com Subject: Re: Fun with date calculations in VFP On Tue, May 8, 2018 at 11:23 AM, Richard Kaye wrote: > Another guy that fixes his typos the 2nd time... π Thanks, Ted! :) Well, the first version ran great in GMail! The second version I actually tried running in VFP ;) ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/cacw6n4vohtam8pgwsywlvd5qw+etru9unygr61gh1j2eg-t...@mail.gmail.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious. Report [OT] Abuse: http://leafe.com/reportAbuse/cacw6n4vohtam8pgwsywlvd5qw+etru9unygr61gh1j2eg-t...@mail.gmail.com ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/dm5pr10mb12444639b38b2c37cad00555d2...@dm5pr10mb1244.namprd10.prod.outlook.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious. ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/18725b8cd2d5d247873a2baf401d4ab2bec93...@ex2010-a-fpl.fpl.LOCAL ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
RE: Fun with date calculations in VFP
lol -- rk -Original Message- From: ProfoxTech On Behalf Of Ted Roche Sent: Tuesday, May 08, 2018 11:28 AM To: profoxt...@leafe.com Subject: Re: Fun with date calculations in VFP On Tue, May 8, 2018 at 11:23 AM, Richard Kaye wrote: > Another guy that fixes his typos the 2nd time... π Thanks, Ted! :) Well, the first version ran great in GMail! The second version I actually tried running in VFP ;) ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/cacw6n4vohtam8pgwsywlvd5qw+etru9unygr61gh1j2eg-t...@mail.gmail.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious. Report [OT] Abuse: http://leafe.com/reportAbuse/cacw6n4vohtam8pgwsywlvd5qw+etru9unygr61gh1j2eg-t...@mail.gmail.com ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/dm5pr10mb12444639b38b2c37cad00555d2...@dm5pr10mb1244.namprd10.prod.outlook.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Re: Fun with date calculations in VFP
On Tue, May 8, 2018 at 11:23 AM, Richard Kaye wrote: > Another guy that fixes his typos the 2nd time... π Thanks, Ted! :) Well, the first version ran great in GMail! The second version I actually tried running in VFP ;) ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/cacw6n4vohtam8pgwsywlvd5qw+etru9unygr61gh1j2eg-t...@mail.gmail.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
RE: Fun with date calculations in VFP
Another guy that fixes his typos the 2nd time... π Thanks, Ted! -- rk -Original Message- From: ProfoxTech On Behalf Of Ted Roche Sent: Tuesday, May 08, 2018 11:12 AM To: profoxt...@leafe.com Subject: Re: Fun with date calculations in VFP Or, cleaned up a bit: FUNCTION olddate(thedate, offset) * parameters: thedate: date to start from * offset: number of years offset, positive or negative * returns: nearest date to the offset that falls on the same day of the week LOCAL thediff, theoffset thediff = DOW(thedate)-DOW(gomonth(thedate, offset*12)) theoffset = IIF(thediff>3, 7-thediff, thediff) RETURN GOMONTH(thedate, offset*12) + theoffset -- Ted Roche Ted Roche & Associates, LLC http://www.tedroche.com ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/dm5pr10mb1244548ca3dacc7605b8306ad2...@dm5pr10mb1244.namprd10.prod.outlook.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Re: Fun with date calculations in VFP
Or, cleaned up a bit: FUNCTION olddate(thedate, offset) * parameters: thedate: date to start from * offset: number of years offset, positive or negative * returns: nearest date to the offset that falls on the same day of the week LOCAL thediff, theoffset thediff = DOW(thedate)-DOW(gomonth(thedate, offset*12)) theoffset = IIF(thediff>3, 7-thediff, thediff) RETURN GOMONTH(thedate, offset*12) + theoffset -- Ted Roche Ted Roche & Associates, LLC http://www.tedroche.com ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/CACW6n4tCYNwN2uJC0i+=jm2GSB57G1vyY=mzq2fvp6+zkth...@mail.gmail.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Re: Fun with date calculations in VFP
On Tue, May 8, 2018 at 9:14 AM, Ted Roche wrote: > So, do you want a function that returns the second Tuesday in May or > one that returns the Tuesday closest to May 8? Both would fit the > specs. > > Date math was one of my many VFP hobbies. There were lots of date math > answers in Ask Advisor. > > GOMONTH() gets you to the year you want, then you can use DOW() to > figure out the day of the week that date has, then add/subtract to get > to the Tuesday you're after. > I know there's a better algorithm to do this, but this might work... function olddate(thedate, offset) * parameters: thedate: date to start from * offset: number of years offset, positive or negative * returns: nearest date to the offset that falls on the same day of the week local thedow, thenewdow, thediff, theoffset thedow = dow(thedate) thenewdow = dow(gomonth(thedate, offset*12)) thediff = thedow - thenewdow theoffset = iff(thediff>3, 7-thediff, thediff) return gomonth(thedate, offset*12) + thediff ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/CACW6n4u4nczhZe8=v3n2zcnattpn2tjdvmdigxbxorpe8xi...@mail.gmail.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Re: Fun with date calculations in VFP
I found a millisecond approach a while back that hasn't given us any issues yet 60480 milliseconds in a week is the fact I base the code on. var date:Date = new Date(, MM, DD); Datetime lastyear = date.setMilliseconds(date.milliseconds - 60480 * 52); On Tue, May 8, 2018 at 8:07 AM, Richard Kaye wrote: > While doing my due diligence on the subject I thought Iβd toss it out here > in case someone already has a function handy that will do this, thus saving > me the effort of thinking too hard too early in the day. π > > Hereβs the goal. I want to take a date, say today, Tuesday May 8, 2018 and > figure out how to return Tuesday, May 9, 2017 or Tuesday May 10, 2016, etc. > This is so I can do some year over year comparisons to transactions that > occurred on the same day of the week a year ago. > > TIA > > -- > > rk > [excessive quoting removed by server] ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/cajidmykf_pvkbd1-jypfs_znfpkaehjykrm9ofvuj0uyxsk...@mail.gmail.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
RE: Fun with date calculations in VFP
I was just looking at your code and noticed the bit at the end seemed to have something missing. π SET DATE BRITISH? What's that? -- rk -Original Message- From: ProfoxTech On Behalf Of Dave Crozier Sent: Tuesday, May 08, 2018 9:29 AM To: profoxt...@leafe.com Subject: RE: Fun with date calculations in VFP Error Fix: The function should read as follows: *** * Mirrors the SQL DateAdd() function * Written By: R.D.Crozier * From an idea in MSDN Forum * Function DateAdd(tcInterval,tnIncrement,tdDateTime) Local strTime As String,strOldExact As String,strOldDate As String,vReturn As Datetime local dDateTime strOldExact = Set("Exact") strOldDate = Set("Date") strOldCentury = Set("Century") Set Date BRITISH Set Exact On dDateTime = Cast(tdDateTime As Datetime) strTime = Substr(Transform(dDateTime),10,8) strTime = Right(Transform(dDateTime),11) tcInterval = Upper(tcInterval) Do Case Case Inlist(tcInterval,"YEAR","YY","") && Years vReturn = Cast(Transform(Gomonth(dDateTime,tnIncrement*12))+" "+strTime As Datetime) Case Inlist(tcInterval,"MONTH","MM","M") && Months vReturn = Cast(Transform(Gomonth(dDateTime,tnIncrement))+" "+strTime As Datetime) Case Inlist(tcInterval,"DAY","DD","D") && Days vReturn = dDateTime + (tnIncrement * 86400) Case Inlist(tcInterval,"HOUR","HH") && Hours vReturn = dDateTime + (tnIncrement * 3600) Case Inlist(tcInterval,"MINUTE","MI","N") && Minutes vReturn = dDateTime + (tnIncrement * 60) Case Inlist(tcInterval,"SECOND","SS","S") && SECONDS vReturn = dDateTime + tnIncrement Case Inlist(tcInterval,"WEEK","WW","WK") && Weeks vReturn = dDateTime + (tnIncrement * 86400 * 7) Otherwise vReturn = dDateTime Endcase Set Date &strOldDate. Set Exact &strOldExact. set century &strOldCentury. do case case Type("tdDateTime")="D" vReturn = Cast(vReturn as Date) * case Type("tdDateTime")="T" vReturn = Cast(vReturn as DateTime) * otherwise * endcase Return vReturn * Endfunc --- This communication and the information it contains is intended for the person or organisation to whom it is addressed. Its contents are confidential and may be protected in law. If you have received this e-mail in error you must not copy, distribute or take any action in reliance on it. Unauthorised use, copying or disclosure of any of it may be unlawful. If you have received this message in error, please notify us immediately by telephone or email. Flexipol Packaging Ltd. has taken every reasonable precaution to minimise the risk of virus transmission through email and therefore any files sent via e-mail will have been checked for known viruses. However, you are advised to run your own virus check before opening any attachments received as Flexipol Packaging Ltd will not in any event accept any liability whatsoever once an e-mail and/or any attachment is received. It is the responsibility of the recipient to ensure that they have adequate virus protection. Flexipol Packaging Ltd. Unit 14 Bentwood Road Carrs Industrial Estate Haslingden Rossendale Lancashire BB4 5HH Tel:01706-222792 Fax: 01706-224683 www.Flexipol.co.uk --- Terms & Conditions: Notwithstanding delivery and the passing of risk in the goods, the property in the goods shall not pass to the buyer until the seller Flexipol Packaging Ltd. ("The Company") has received in cash or cleared funds payment in full of the price of the goods and all other goods agreed to be sold by the seller to the buyer for which payment is then due. Until such time as the property in the goods passes to the buyer, the buyer shall hold the goods as the seller's fiduciary agent and bailee and keep the goods separate from those of the buyer and third parties and properly stored protected and insured and identified as the seller's property but shall be entitled to resell or use the goods in the ordinary course of its business. Until such time as the property in the goods passes to the buyer the seller shall be entitled at any time --- This communication and the information it contains is intended for the person or organisation to whom it is addressed. Its contents are confidential and may be protected in law. If you have received this e-mail in error you must not copy, distribute or take any action in reliance on it. Unauthorised use, copying or disclosure of any of it may be unlawful. If you have received this message in error, please notify us immediately by telephone or email. Flexip
RE: Fun with date calculations in VFP
Error Fix: The function should read as follows: *** * Mirrors the SQL DateAdd() function * Written By: R.D.Crozier * From an idea in MSDN Forum * Function DateAdd(tcInterval,tnIncrement,tdDateTime) Local strTime As String,strOldExact As String,strOldDate As String,vReturn As Datetime local dDateTime strOldExact = Set("Exact") strOldDate = Set("Date") strOldCentury = Set("Century") Set Date BRITISH Set Exact On dDateTime = Cast(tdDateTime As Datetime) strTime = Substr(Transform(dDateTime),10,8) strTime = Right(Transform(dDateTime),11) tcInterval = Upper(tcInterval) Do Case Case Inlist(tcInterval,"YEAR","YY","") && Years vReturn = Cast(Transform(Gomonth(dDateTime,tnIncrement*12))+" "+strTime As Datetime) Case Inlist(tcInterval,"MONTH","MM","M") && Months vReturn = Cast(Transform(Gomonth(dDateTime,tnIncrement))+" "+strTime As Datetime) Case Inlist(tcInterval,"DAY","DD","D") && Days vReturn = dDateTime + (tnIncrement * 86400) Case Inlist(tcInterval,"HOUR","HH") && Hours vReturn = dDateTime + (tnIncrement * 3600) Case Inlist(tcInterval,"MINUTE","MI","N") && Minutes vReturn = dDateTime + (tnIncrement * 60) Case Inlist(tcInterval,"SECOND","SS","S") && SECONDS vReturn = dDateTime + tnIncrement Case Inlist(tcInterval,"WEEK","WW","WK") && Weeks vReturn = dDateTime + (tnIncrement * 86400 * 7) Otherwise vReturn = dDateTime Endcase Set Date &strOldDate. Set Exact &strOldExact. set century &strOldCentury. do case case Type("tdDateTime")="D" vReturn = Cast(vReturn as Date) * case Type("tdDateTime")="T" vReturn = Cast(vReturn as DateTime) * otherwise * endcase Return vReturn * Endfunc --- This communication and the information it contains is intended for the person or organisation to whom it is addressed. Its contents are confidential and may be protected in law. If you have received this e-mail in error you must not copy, distribute or take any action in reliance on it. Unauthorised use, copying or disclosure of any of it may be unlawful. If you have received this message in error, please notify us immediately by telephone or email. Flexipol Packaging Ltd. has taken every reasonable precaution to minimise the risk of virus transmission through email and therefore any files sent via e-mail will have been checked for known viruses. However, you are advised to run your own virus check before opening any attachments received as Flexipol Packaging Ltd will not in any event accept any liability whatsoever once an e-mail and/or any attachment is received. It is the responsibility of the recipient to ensure that they have adequate virus protection. Flexipol Packaging Ltd. Unit 14 Bentwood Road Carrs Industrial Estate Haslingden Rossendale Lancashire BB4 5HH Tel:01706-222792 Fax: 01706-224683 www.Flexipol.co.uk --- Terms & Conditions: Notwithstanding delivery and the passing of risk in the goods, the property in the goods shall not pass to the buyer until the seller Flexipol Packaging Ltd. ("The Company") has received in cash or cleared funds payment in full of the price of the goods and all other goods agreed to be sold by the seller to the buyer for which payment is then due. Until such time as the property in the goods passes to the buyer, the buyer shall hold the goods as the seller's fiduciary agent and bailee and keep the goods separate from those of the buyer and third parties and properly stored protected and insured and identified as the seller's property but shall be entitled to resell or use the goods in the ordinary course of its business. Until such time as the property in the goods passes to the buyer the seller shall be entitled at any time --- This communication and the information it contains is intended for the person or organisation to whom it is addressed. Its contents are confidential and may be protected in law. If you have received this e-mail in error you must not copy, distribute or take any action in reliance on it. Unauthorised use, copying or disclosure of any of it may be unlawful. If you have received this message in error, please notify us immediately by telephone or email. Flexipol Packaging Ltd. has taken every reasonable precaution to minimise the risk of virus transmission through email and therefore any files sent via e-mail will have been checked for known viruses. However, you are advised to run your own virus check before opening any attachments received as Flexipol Packaging Ltd will
RE: Fun with date calculations in VFP
The latter. And that was the approach I was just working through. Thanks to both you and Dave for chiming in. -- rk -Original Message- From: ProfoxTech On Behalf Of Ted Roche Sent: Tuesday, May 08, 2018 9:15 AM To: profoxt...@leafe.com Subject: Re: Fun with date calculations in VFP So, do you want a function that returns the second Tuesday in May or one that returns the Tuesday closest to May 8? Both would fit the specs. Date math was one of my many VFP hobbies. There were lots of date math answers in Ask Advisor. GOMONTH() gets you to the year you want, then you can use DOW() to figure out the day of the week that date has, then add/subtract to get to the Tuesday you're after. On Tue, May 8, 2018 at 9:07 AM, Richard Kaye wrote: > While doing my due diligence on the subject I thought Iβd toss it out here in > case someone already has a function handy that will do this, thus saving me > the effort of thinking too hard too early in the day. π > > Hereβs the goal. I want to take a date, say today, Tuesday May 8, 2018 and > figure out how to return Tuesday, May 9, 2017 or Tuesday May 10, 2016, etc. > This is so I can do some year over year comparisons to transactions that > occurred on the same day of the week a year ago. > > TIA > > -- > > rk ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/dm5pr10mb12445e58187567ea120d9b7fd2...@dm5pr10mb1244.namprd10.prod.outlook.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Re: Fun with date calculations in VFP
So, do you want a function that returns the second Tuesday in May or one that returns the Tuesday closest to May 8? Both would fit the specs. Date math was one of my many VFP hobbies. There were lots of date math answers in Ask Advisor. GOMONTH() gets you to the year you want, then you can use DOW() to figure out the day of the week that date has, then add/subtract to get to the Tuesday you're after. On Tue, May 8, 2018 at 9:07 AM, Richard Kaye wrote: > While doing my due diligence on the subject I thought Iβd toss it out here in > case someone already has a function handy that will do this, thus saving me > the effort of thinking too hard too early in the day. π > > Hereβs the goal. I want to take a date, say today, Tuesday May 8, 2018 and > figure out how to return Tuesday, May 9, 2017 or Tuesday May 10, 2016, etc. > This is so I can do some year over year comparisons to transactions that > occurred on the same day of the week a year ago. > > TIA > > -- > > rk > [excessive quoting removed by server] ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/cacw6n4sgk5rh6o6s-gwlx2n3qki5qd+zp-ssosu339fqvbt...@mail.gmail.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
RE: Fun with date calculations in VFP
clear set century on dDate=Date() ? DateAdd("YY", 5, dDate) ? DateAdd("WEEK", 5, dDate) * return * Mirrors TSQL DateAdd() Function * Example: * ? DateAdd("YY", 2, Date()) * Function DateAdd(tcInterval,tnIncrement,tdDateTime) Local strTime As String,strOldExact As String,strOldDate As String,vReturn As Datetime strOldExact = Set("Exact") strOldDate = Set("Date") strOldCentury = Set("Century") Set Date BRITISH Set Exact On tdDateTime = Cast(tdDateTime As Datetime) strTime = Substr(Transform(tdDateTime),10,8) strTime = Right(Transform(tdDateTime),11) tcInterval = Upper(tcInterval) Do Case Case Inlist(tcInterval,"YEAR","YY","") && Years vReturn = Cast(Transform(Gomonth(tdDateTime,tnIncrement*12))+" "+strTime As Datetime) Case Inlist(tcInterval,"MONTH","MM","M") && Months vReturn = Cast(Transform(Gomonth(tdDateTime,tnIncrement))+" "+strTime As Datetime) Case Inlist(tcInterval,"DAY","DD","D") && Days vReturn = tdDateTime + (tnIncrement * 86400) Case Inlist(tcInterval,"HOUR","HH") && Hours vReturn = tdDateTime + (tnIncrement * 3600) Case Inlist(tcInterval,"MINUTE","MI","N") && Minutes vReturn = tdDateTime + (tnIncrement * 60) Case Inlist(tcInterval,"SECOND","SS","S") && SECONDS vReturn = tdDateTime + tnIncrement Case Inlist(tcInterval,"WEEK","WW","WK") && Weeks vReturn = tdDateTime + (tnIncrement * 86400 * 7) Otherwise vReturn = tdDateTime Endcase Set Date &strOldDate. Set Exact &strOldExact. set century &strOldCentury. if Type("tdDateTime") Return vReturn * endfunc --- This communication and the information it contains is intended for the person or organisation to whom it is addressed. Its contents are confidential and may be protected in law. If you have received this e-mail in error you must not copy, distribute or take any action in reliance on it. Unauthorised use, copying or disclosure of any of it may be unlawful. If you have received this message in error, please notify us immediately by telephone or email. Flexipol Packaging Ltd. has taken every reasonable precaution to minimise the risk of virus transmission through email and therefore any files sent via e-mail will have been checked for known viruses. However, you are advised to run your own virus check before opening any attachments received as Flexipol Packaging Ltd will not in any event accept any liability whatsoever once an e-mail and/or any attachment is received. It is the responsibility of the recipient to ensure that they have adequate virus protection. Flexipol Packaging Ltd. Unit 14 Bentwood Road Carrs Industrial Estate Haslingden Rossendale Lancashire BB4 5HH Tel:01706-222792 Fax: 01706-224683 www.Flexipol.co.uk --- Terms & Conditions: Notwithstanding delivery and the passing of risk in the goods, the property in the goods shall not pass to the buyer until the seller Flexipol Packaging Ltd. ("The Company") has received in cash or cleared funds payment in full of the price of the goods and all other goods agreed to be sold by the seller to the buyer for which payment is then due. Until such time as the property in the goods passes to the buyer, the buyer shall hold the goods as the seller's fiduciary agent and bailee and keep the goods separate from those of the buyer and third parties and properly stored protected and insured and identified as the seller's property but shall be entitled to resell or use the goods in the ordinary course of its business. Until such time as the property in the goods passes to the buyer the seller shall be entitled at any time ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/18725b8cd2d5d247873a2baf401d4ab2bec93...@ex2010-a-fpl.fpl.LOCAL ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Fun with date calculations in VFP
While doing my due diligence on the subject I thought Iβd toss it out here in case someone already has a function handy that will do this, thus saving me the effort of thinking too hard too early in the day. π Hereβs the goal. I want to take a date, say today, Tuesday May 8, 2018 and figure out how to return Tuesday, May 9, 2017 or Tuesday May 10, 2016, etc. This is so I can do some year over year comparisons to transactions that occurred on the same day of the week a year ago. TIA -- rk ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/dm5pr10mb12440520757e4274ba860c2ad2...@dm5pr10mb1244.namprd10.prod.outlook.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Re: [NF] No Internet Connect
Is your desktop also using wifi connection? Weird that only the laptop and cell phone could talk to the wireless router. If your desktop used wired LAN, set a static IP and see if it could ping the router. Since you are still in 1709, it's not the recent 1803 upgrade. On Mon, May 7, 2018 at 11:11 PM, Charles Hart Enzer, M.D. wrote: > > Laptop and cell phone get the internet > Question about upgrade good > Didn't see it in Programs on Control Panel > * > Now, still 1709 > > My Restore Points only go back to 5/4 when the problem of connecting began. > > Don't know how to get earlier Restore Points. -- .~. Might, Courage, Vision. SINCERITY! / v \ 64-bit Fedora 25 Server Spin /( _ )\ http://sites.google.com/site/changmw ^ ^ May the Force and farces be with you! ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/CAGv=MJDJLVwK9Uhx4=v1ip+2zm9xj259cr5q+w3dsa9bmwm...@mail.gmail.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.