Discussion:
Fun with date calculations in VFP
Richard Kaye
2018-05-08 21:39:34 UTC
Permalink
I owe you a Scotch next time you're in the area.

--

rk

-----Original Message-----
From: ProfoxTech <profoxtech-***@leafe.com> On Behalf Of Ted Roche
Sent: Tuesday, May 08, 2018 5:15 PM
To: ***@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 <***@gmail.com> 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 <***@gmail.com> 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 <***@invaluable.com> 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 <profoxtech-***@leafe.com> On Behalf Of Ted Roche
>>> Sent: Tuesday, May 08, 2018 3:25 PM
>>> To: ***@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 <***@invaluable.com> 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.0000.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 <profoxtech-***@leafe.com> On Behalf Of Gene Wirchenko
>>>> Sent: Tuesday, May 08, 2018 12:46 PM
>>>> To: ***@leafe.com
>>>> Subject: RE: Fun with date calculations in VFP
>>>>
>>>> At 06:27 2018-05-08, Richard Kaye <***@invaluable.com> 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: ***@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/***@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.
Ted Roche
2018-05-09 15:39:34 UTC
Permalink
On Tue, May 8, 2018 at 5:39 PM, Richard Kaye <***@invaluable.com> wrote:
> I owe you a Scotch next time you're in the area.
>

Deal!

--
Ted Roche & Associates, LLC
http://www.tedroche.com

_______________________________________________
Post Messages to: ***@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/***@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.
Eric Selje
2018-05-15 20:20:09 UTC
Permalink
I've started a class for a C# like DateTime static class here:
https://github.com/eselje/FoxTypes/blob/master/FT_DATETIME.md

I may steal some of the ideas here to embellish it, but if you have time
and want to contribute please clone this repo and submit a pull request
when done. It's pretty handy.

Eric


On Wed, May 9, 2018 at 10:39 AM, Ted Roche <***@gmail.com> wrote:

> On Tue, May 8, 2018 at 5:39 PM, Richard Kaye <***@invaluable.com> wrote:
> > I owe you a Scotch next time you're in the area.
> >
>
> Deal!
>
> --
> Ted Roche & Associates, LLC
> http://www.tedroche.com
>
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@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/CAAwxvU=9etoHOksAaZ4+S7HZPGuLs=5vmC9-***@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.
Jürgen Wondzinski
2018-05-16 06:42:22 UTC
Permalink
Hi Eric,

something to add to your currently blank function in your class:

FUNCTION IsLeapYear (iYear)
RETURN NOT EMPTY(DATE(iYear,2,29))


wOOdy


-----Ursprüngliche Nachricht-----
Von: ProFox <profox-***@leafe.com> Im Auftrag von Eric Selje
Gesendet: Dienstag, 15. Mai 2018 22:20
An: ProFox Email List <***@leafe.com>
Betreff: Re: Fun with date calculations in VFP

I've started a class for a C# like DateTime static class here:
https://github.com/eselje/FoxTypes/blob/master/FT_DATETIME.md



_______________________________________________
Post Messages to: ***@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/003c01d3ece1$0bb64e10$2322ea30$@wondzinski.de
** 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.
Eric Selje
2018-05-16 21:34:49 UTC
Permalink
Will do!

On Wed, May 16, 2018 at 1:42 AM, Jürgen Wondzinski <***@wondzinski.de>
wrote:

> Hi Eric,
>
> something to add to your currently blank function in your class:
>
> FUNCTION IsLeapYear (iYear)
> RETURN NOT EMPTY(DATE(iYear,2,29))
>
>
> wOOdy
>
>
> -----Ursprüngliche Nachricht-----
> Von: ProFox <profox-***@leafe.com> Im Auftrag von Eric Selje
> Gesendet: Dienstag, 15. Mai 2018 22:20
> An: ProFox Email List <***@leafe.com>
> Betreff: Re: Fun with date calculations in VFP
>
> I've started a class for a C# like DateTime static class here:
> https://github.com/eselje/FoxTypes/blob/master/FT_DATETIME.md
>
>
>
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@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/CAAwxvUkG0dd9k0sgiCvMh=WCfReHUNCvK=Bh2tL4F4xC+-***@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 obvi
Ted Roche
2018-05-21 19:53:32 UTC
Permalink
On Mon, May 21, 2018 at 3:37 PM, Vince Teachout <***@taconic.net> wrote:
>
> nb: Don't lose vfp install disk before then!
>

Gotcha covered: https://imgur.com/a/NPMsnUL

Hmm... might need to find a disk drive too. And a controller.
Edge-connector cable... hmm....

--
Ted Roche
Ted Roche & Associates, LLC
http://www.tedroche.com

_______________________________________________
Post Messages to: ***@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/***@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.
Eric Selje
2018-05-16 22:29:08 UTC
Permalink
Updated. Clearly a lot of stuff left to do on this class! I got distracted
by "work" but feel free to clone and contribute.

set proc to datetime addi
_vfp.addoboject("DateTime", "DateTime") && Now it's always available
? _vfp.DateTime.FirstDayOfMonth() && 05/01/2018
? _vfp.DateTime.FirstDayOfMonth(gomonth(date(),1) && 06/01/2018
? _vfp.DateTime.LastDayOfMonth() && 05/31/2018
? _vfp.DateTime.LastDayOfMonth(2012,2) && 02/29/2012
? _vfp.DateTime.IsLeapYear(2012) && .t.

Eric

On Wed, May 16, 2018 at 5:02 PM, Ted Roche <***@gmail.com> wrote:

> LastDayOfMonth() or LDOM back in my 8.3 days, was always a popular request:
>
> http://fox.wikis.com/wc.dll?Wiki~FindingTheLastDayOfTheMonth~VB
>
> --
> Ted Roche
> Ted Roche & Associates, LLC
> http://www.tedroche.com
>
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@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/CAAwxvUnvU09O+g4DFQxm-piP1Pp_RsX6L-F35zq4FCbz-***@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.
Paul Newton
2018-05-18 13:43:12 UTC
Permalink
Hi Eric

I've taken a look at your DateTime class and, as you say, it's a work in progress. Would you be kind enough to keep us informed of updates?

Many Thanks

Paul Newton

-----Original Message-----
From: ProFox [mailto:profox-***@leafe.com] On Behalf Of Eric Selje
Sent: 16 May 2018 23:29
To: ProFox Email List <***@leafe.com>
Subject: Re: Fun with date calculations in VFP

Updated. Clearly a lot of stuff left to do on this class! I got distracted by "work" but feel free to clone and contribute.

set proc to datetime addi
_vfp.addoboject("DateTime", "DateTime") && Now it's always available
? _vfp.DateTime.FirstDayOfMonth() && 05/01/2018
? _vfp.DateTime.FirstDayOfMonth(gomonth(date(),1) && 06/01/2018
? _vfp.DateTime.LastDayOfMonth() && 05/31/2018
? _vfp.DateTime.LastDayOfMonth(2012,2) && 02/29/2012
? _vfp.DateTime.IsLeapYear(2012) && .t.

Eric

On Wed, May 16, 2018 at 5:02 PM, Ted Roche <***@gmail.com> wrote:

> LastDayOfMonth() or LDOM back in my 8.3 days, was always a popular request:
>
> http://fox.wikis.com/wc.dll?Wiki~FindingTheLastDayOfTheMonth~VB
>
> --
> Ted Roche
> Ted Roche & Associates, LLC
> http://www.tedroche.com
>
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@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/***@BY2PR0201MB1847.namprd02.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.
Ted Roche
2018-05-17 10:22:49 UTC
Permalink
You have a set of Add functions: AddYears, AddDays, AddHours, Minutes,
Seconds, Ticks... where's AddMonth, besides the obvious GOMONTH()?

Time support native in VFP has always been weak. I wrote a s2hms and
hms2s to convert between seconds and HH:MM:SS strings.

DTOT converts a Data to a datetime by setting time to 00:00:00. It
would be handy to have the ability to set the time as well, even
though it's pretty much the trivial

RETURN DTOT(thedate)+hms2s(thetime)

A pretty print would be handy, I don't know C#, but PHP et all has
fprint with a unix-standard-y format string, String.Format does the
same in C# apparently:

http://www.csharp-examples.net/string-format-datetime/
https://secure.php.net/manual/en/datetime.format.php

I can't tell you how many times I've written a UDF or inline code to
generate variations on "Monday, December 31, 1999 12:34:56 am" -
having that in one place would be handy.


On Tue, May 15, 2018 at 4:20 PM, Eric Selje <***@saltydogllc.com> wrote:
> I've started a class for a C# like DateTime static class here:
> https://github.com/eselje/FoxTypes/blob/master/FT_DATETIME.md
>
> I may steal some of the ideas here to embellish it, but if you have time
> and want to contribute please clone this repo and submit a pull request
> when done. It's pretty handy.
>
> Eric
>
>
> On Wed, May 9, 2018 at 10:39 AM, Ted Roche <***@gmail.com> wrote:
>
>> On Tue, May 8, 2018 at 5:39 PM, Richard Kaye <***@invaluable.com> wrote:
>> > I owe you a Scotch next time you're in the area.
>> >
>>
>> Deal!
>>
>> --
>> Ted Roche & Associates, LLC
>> http://www.tedroche.com
>>
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@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/CACW6n4tmNA1QnTLTXSREkqQr8x+kbb9PQJhJpHr+***@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.
Jürgen Wondzinski
2018-05-17 15:07:39 UTC
Permalink
Hmmm.. You know that "SaltyDog" is actually Eric's page ?

wOOdy


-----Ursprüngliche Nachricht-----
Von: ProFox [mailto:profox-***@leafe.com] Im Auftrag von Alan Bourke
Gesendet: Donnerstag, 17. Mai 2018 14:12
An: ***@leafe.com
Betreff: Re: Fun with date calculations in VFP

There's a VFP implementation of the C# String.Format() here:
http://saltydogllc.com/string-format-for-visual-foxpro/


--
Alan Bourke
alanpbourke (at) fastmail (dot) fm

[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@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/001001d3edf0$cc7c52b0$6574f810$@wondzinski.de
** 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.
Ted Roche
2018-05-17 14:23:46 UTC
Permalink
On Thu, May 17, 2018 at 8:11 AM, Alan Bourke <***@fastmail.fm> wrote:
> There's a VFP implementation of the C# String.Format() here: http://saltydogllc.com/string-format-for-visual-foxpro/

Cool! Check that off the list!


--
Ted Roche
Ted Roche & Associates, LLC
http://www.tedroche.com

_______________________________________________
Post Messages to: ***@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/CACW6n4tXdU8UYRRPj4SGtONzc_jyot-***@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.
Jürgen Wondzinski
2018-05-18 18:26:43 UTC
Permalink
This FirstDayOfQuarter and siblings is much easier to do:

*******************************************
FUNCTION GoQuarter(dDate, cValue)
* "L" = (L)ast day of dDate's Quarter
* "F" = (F)irst day of dDate's Quarter
* "N" = first day of (n)ext dDate's Quarter
* "P" = first day of (p)previous dDate's Quarter
*******************************************

cValue = EVL(cValue, "F")
LOCAL dResult
DO CASE
CASE cValue = "L"
dResult = GOMONTH(dDate,(CEILING(MONTH(dDate)/3)*3)-MONTH(dDate)+1)-DAY(dDate)
CASE cValue = "F"
dResult = GOMONTH(dDate,(CEILING(MONTH(dDate)/3)*3)-MONTH(dDate)-2)-DAY(dDate)+1
CASE cValue = "N"
dResult = GOMONTH(dDate,(CEILING(MONTH(dDate)/3)*3)-MONTH(dDate)+1)-DAY(dDate)+1
CASE cValue = "P"
dResult = GOMONTH(dDate,(CEILING(MONTH(dDate)/3)*3)-MONTH(dDate)-5)-DAY(dDate)+1
ENDCASE
RETURN dResult

wOOdy


"*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`.Visual FoxPro: It's magic !
(¸.·``··*




-----Ursprüngliche Nachricht-----
Von: ProFox <profox-***@leafe.com> Im Auftrag von Frank Cazabon
Gesendet: Freitag, 18. Mai 2018 18:41
An: ***@leafe.com
Betreff: Re: Fun with date calculations in VFP

Lots of spare time today so some hopefully constructive criticism: :)

I would redo some of that code to get away from CTOD() as that will fail
depending on SET STRICTDATE and if SET DATE is anything besides MDY.

I have a feeling that your first day of week and last day of week will
be incorrect in situations with SET FDOW.

I think PARAMETERS() is also advised against and PCOUNT() is better.

I would also move each function into its own program.

For example FirstDayOfQuarter.prg would be:

LPARAMETERS tdDate

LOCAL lnMonth as Integer, lnYear as Integer, ldDate as Date
if PCOUNT()=0 then
m.tdDate = date()
endif
m.lnYear = YEAR(m.tdDate)
m.lnMonth = MONTH(m.tdDate)
DO CASE
CASE BETWEEN(m.lnMonth,1,3)
m.ldDate = DATE(m.lnYear, 1, 1)
CASE BETWEEN(m.lnMonth,4,6)
m.ldDate = DATE(m.lnYear, 4, 1)
CASE BETWEEN(m.lnMonth,7,9)
m.ldDate = DATE(m.lnYear, 7, 1)
OTHERWISE && CASE BETWEEN(m.lnMonth,10,12)
m.ldDate = DATE(m.lnYear, 10, 1)
ENDCASE
return ldDate


Frank.


_______________________________________________
Post Messages to: ***@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/017001d3eed5$c625d810$52718830$@wondzinski.de
** 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 f
Eric Selje
2018-05-18 20:52:47 UTC
Permalink
Hi everyone! Yes, I'm the Salty Dog page, and this library is an attempt to
replicate what's in C#'s static classes, which are really powerful to have
around.

The STRING one is mostly complete but I just got started on the DATETIME
and it's definitely a work in progress. To stay on top of it, you can click
the "Watch" button on the GitHub page and you'll get notifications whenever
a new commit happens (I've done a lot just in the last few days as I've
been using this library as I work on another class to validate JWTs in
FoxPro.

I really like all the feedback! Another thing you can do is submit an issue
on the GitHub page itself (and then get notified when it's handled) or
better yet, clone the repo and make some contributions! :)

Eric



On Fri, May 18, 2018 at 1:26 PM, Jürgen Wondzinski <***@wondzinski.de>
wrote:

> This FirstDayOfQuarter and siblings is much easier to do:
>
> *******************************************
> FUNCTION GoQuarter(dDate, cValue)
> * "L" = (L)ast day of dDate's Quarter
> * "F" = (F)irst day of dDate's Quarter
> * "N" = first day of (n)ext dDate's Quarter
> * "P" = first day of (p)previous dDate's Quarter
> *******************************************
>
> cValue = EVL(cValue, "F")
> LOCAL dResult
> DO CASE
> CASE cValue = "L"
> dResult = GOMONTH(dDate,(CEILING(MONTH(
> dDate)/3)*3)-MONTH(dDate)+1)-DAY(dDate)
> CASE cValue = "F"
> dResult = GOMONTH(dDate,(CEILING(MONTH(
> dDate)/3)*3)-MONTH(dDate)-2)-DAY(dDate)+1
> CASE cValue = "N"
> dResult = GOMONTH(dDate,(CEILING(MONTH(
> dDate)/3)*3)-MONTH(dDate)+1)-DAY(dDate)+1
> CASE cValue = "P"
> dResult = GOMONTH(dDate,(CEILING(MONTH(
> dDate)/3)*3)-MONTH(dDate)-5)-DAY(dDate)+1
> ENDCASE
> RETURN dResult
>
> wOOdy
>
>
> "*´¨)
> ¸.·´¸.·*´¨) ¸.·*¨)
> (¸.·´. (¸.·` *
> .·`.Visual FoxPro: It's magic !
> (¸.·``··*
>
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: ProFox <profox-***@leafe.com> Im Auftrag von Frank Cazabon
> Gesendet: Freitag, 18. Mai 2018 18:41
> An: ***@leafe.com
> Betreff: Re: Fun with date calculations in VFP
>
> Lots of spare time today so some hopefully constructive criticism: :)
>
> I would redo some of that code to get away from CTOD() as that will fail
> depending on SET STRICTDATE and if SET DATE is anything besides MDY.
>
> I have a feeling that your first day of week and last day of week will
> be incorrect in situations with SET FDOW.
>
> I think PARAMETERS() is also advised against and PCOUNT() is better.
>
> I would also move each function into its own program.
>
> For example FirstDayOfQuarter.prg would be:
>
> LPARAMETERS tdDate
>
> LOCAL lnMonth as Integer, lnYear as Integer, ldDate as Date
> if PCOUNT()=0 then
> m.tdDate = date()
> endif
> m.lnYear = YEAR(m.tdDate)
> m.lnMonth = MONTH(m.tdDate)
> DO CASE
> CASE BETWEEN(m.lnMonth,1,3)
> m.ldDate = DATE(m.lnYear, 1, 1)
> CASE BETWEEN(m.lnMonth,4,6)
> m.ldDate = DATE(m.lnYear, 4, 1)
> CASE BETWEEN(m.lnMonth,7,9)
> m.ldDate = DATE(m.lnYear, 7, 1)
> OTHERWISE && CASE BETWEEN(m.lnMonth,10,12)
> m.ldDate = DATE(m.lnYear, 10, 1)
> ENDCASE
> return ldDate
>
>
> Frank.
>
>
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@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/CAAwxvUm-Mj+cv4v+aW=8Q+pxsdZzLkJtK7FxaXcWM-***@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
Paul Newton
2018-05-21 10:46:11 UTC
Permalink
If you want, for example, the last Friday of the month you could use
LastDayOfMonth(Date(),"Friday") or LastDayOfMonth(5,2018,"Friday")

Function LastDayOfMonth(tuParm1, tuParm2, tuParm3)

Local ldLastDate,lcDayOfWeek,loDaysOfWeek
ldLastDate = {}
If (Pcount() = 3 And Vartype(tuParm3) = "C") Or (Pcount() = 2 And Vartype(tuParm2) = "C")
lcDayOfWeek = Iif(Pcount()=2,tuParm2,tuParm3)
If InList(lcDayOfWeek,"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
loDaysOfWeek = CreateObject("Collection")
loDaysOfWeek.Add(1,"Sunday")
loDaysOfWeek.Add(2,"Monday")
loDaysOfWeek.Add(3,"Tuesday")
loDaysOfWeek.Add(4,"Wednesday")
loDaysOfWeek.Add(5,"Thursday")
loDaysOfWeek.Add(6,"Friday")
loDaysOfWeek.Add(7,"Saturday")
EndIf
EndIf
Do Case
Case InList(Vartype(tuParm1),"D","T")
ldLastDate = Gomonth(tuParm1,1)-Day(tuParm1)
Case Vartype(tuParm1) = "N" And Vartype(tuParm2) = "N"
ldLastDate = Date(tuParm2,tuParm1+1,1)-1
EndCase
If Not Empty(ldLastdate) And Not Empty(lcDayOfWeek)
ldLastDate = ldLastDate - Mod((7-(loDaysOfWeek.Item(lcDayOfWeek) - loDaysOfWeek.Item(CDOW(ldLastDate)))),7)
EndIf
Return ldLastDate

-----Original Message-----
From: ProFox [mailto:profox-***@leafe.com] On Behalf Of Ted Roche
Sent: 20 May 2018 20:32
To: ***@leafe.com
Subject: Re: Fun with date calculations in VFP

On Sun, May 20, 2018 at 1:39 PM, Gene Wirchenko <***@telus.net> wrote:

> thedate=date(9999,12,31) && Handle this extreme case.

And that, kids, is why we call it "The Y10K crisis..."

--
Ted Roche
Ted Roche & Associates, LLC
http://www.tedroche.com

[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@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/***@SN1PR0201MB1856.namprd02.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.
Gene Wirchenko
2018-05-22 02:03:20 UTC
Permalink
At 12:31 2018-05-20, Ted Roche <***@gmail.com> wrote:
>On Sun, May 20, 2018 at 1:39 PM, Gene Wirchenko <***@telus.net> wrote:
>
> > thedate=date(9999,12,31) && Handle this extreme case.
>
>And that, kids, is why we call it "The Y10K crisis..."

It is not a crisis yet. You have to ignore it for some millennia yet.

Sincerely,

Gene Wirchenko


_______________________________________________
Post Messages to: ***@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/***@mtlp000083
** 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.
Paul H. Tarver
2018-05-22 15:38:45 UTC
Permalink
I'm starting to feel the panic rise...No clients calling yet, but it's
coming...

Paul H. Tarver

-----Original Message-----
From: ProfoxTech [mailto:profoxtech-***@leafe.com] On Behalf Of Gene
Wirchenko
Sent: Monday, May 21, 2018 9:03 PM
To: ***@leafe.com
Subject: Re: Fun with date calculations in VFP

At 12:31 2018-05-20, Ted Roche <***@gmail.com> wrote:
>On Sun, May 20, 2018 at 1:39 PM, Gene Wirchenko <***@telus.net> wrote:
>
> > thedate=date(9999,12,31) && Handle this extreme case.
>
>And that, kids, is why we call it "The Y10K crisis..."

It is not a crisis yet. You have to ignore it for some millennia yet.

Sincerely,

Gene Wirchenko


[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@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/158501d3f1e2$f90a96c0$eb1fc440$@tpcqpc.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.
Gene Wirchenko
2018-05-23 01:41:17 UTC
Permalink
At 08:38 2018-05-22, "Paul H. Tarver" <***@tpcqpc.com> wrote:

>-----Original Message-----
>From: ProfoxTech [mailto:profoxtech-***@leafe.com] On Behalf Of Gene
>Wirchenko
>Sent: Monday, May 21, 2018 9:03 PM
>To: ***@leafe.com
>Subject: Re: Fun with date calculations in VFP
>
>At 12:31 2018-05-20, Ted Roche <***@gmail.com> wrote:
> >On Sun, May 20, 2018 at 1:39 PM, Gene Wirchenko <***@telus.net> wrote:
> >
> > > thedate=date(9999,12,31) && Handle this extreme case.
> >
> >And that, kids, is why we call it "The Y10K crisis..."
>
> It is not a crisis yet. You have to ignore it for some millennia yet.

>I'm starting to feel the panic rise...No clients calling yet, but it's
>coming...

You have to ignore it for millennia, Paul! Show some
professionality or unprofessionality or something.

Sincerely,

Gene Wirchenko



_______________________________________________
Post Messages to: ***@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/***@mtlp000085
** 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.
Paul H. Tarver
2018-05-23 15:04:35 UTC
Permalink
Lol

Paul H. Tarver

-----Original Message-----
From: ProfoxTech [mailto:profoxtech-***@leafe.com] On Behalf Of Gene
Wirchenko
Sent: Tuesday, May 22, 2018 8:41 PM
To: ***@leafe.com
Subject: RE: Fun with date calculations in VFP

At 08:38 2018-05-22, "Paul H. Tarver" <***@tpcqpc.com> wrote:

>-----Original Message-----
>From: ProfoxTech [mailto:profoxtech-***@leafe.com] On Behalf Of Gene
>Wirchenko
>Sent: Monday, May 21, 2018 9:03 PM
>To: ***@leafe.com
>Subject: Re: Fun with date calculations in VFP
>
>At 12:31 2018-05-20, Ted Roche <***@gmail.com> wrote:
> >On Sun, May 20, 2018 at 1:39 PM, Gene Wirchenko <***@telus.net> wrote:
> >
> > > thedate=date(9999,12,31) && Handle this extreme case.
> >
> >And that, kids, is why we call it "The Y10K crisis..."
>
> It is not a crisis yet. You have to ignore it for some millennia
yet.

>I'm starting to feel the panic rise...No clients calling yet, but it's
>coming...

You have to ignore it for millennia, Paul! Show some
professionality or unprofessionality or something.

Sincerely,

Gene Wirchenko



[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@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/1f3c01d3f2a7$5d4612d0$17d23870$@tpcqpc.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.
m***@mbsoftwaresolutions.com
2018-05-29 16:35:00 UTC
Permalink
On 2018-05-21 15:37, Vince Teachout wrote:
> On 05/20/18 3:31 PM, Ted Roche wrote:
>> On Sun, May 20, 2018 at 1:39 PM, Gene Wirchenko <***@telus.net>
>> wrote:
>>
>>> thedate=date(9999,12,31) && Handle this extreme case.
>>
>> And that, kids, is why we call it "The Y10K crisis..."
>
> I looking forward to all the $$$$ I'm going to make when people call
> me in from retirement to fix all their old VFP programs before
> midnight 9999! Can we say "Gouging rates?"
>
> nb: Don't lose vfp install disk before then!



You must be going to do cryogenic deep freeze!

_______________________________________________
Post Messages to: ***@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/***@mbsoftwaresolutions.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.
Stephen Russell
2018-05-29 17:04:32 UTC
Permalink
Who has anything like a disk drive on a laptop today?

On Mon, May 21, 2018 at 2:37 PM, Vince Teachout <***@taconic.net> wrote:

> On 05/20/18 3:31 PM, Ted Roche wrote:
>
>> On Sun, May 20, 2018 at 1:39 PM, Gene Wirchenko <***@telus.net> wrote:
>>
>> thedate=date(9999,12,31) && Handle this extreme case.
>>>
>>
>> And that, kids, is why we call it "The Y10K crisis..."
>>
>
> I looking forward to all the $$$$ I'm going to make when people call me in
> from retirement to fix all their old VFP programs before midnight 9999!
> Can we say "Gouging rates?"
>
> nb: Don't lose vfp install disk before then!
>
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
>
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@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/CAJidMY+PeCoW309OaBM3MOeWpbETOKqY_Z2NtmBzsE9dF-***@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.
Vince Teachout
2018-05-29 17:34:45 UTC
Permalink
On 05/29/18 1:04 PM, Stephen Russell wrote:
> Who has anything like a disk drive on a laptop today?

Good point. You think that problem might get worse by 9,999 A.D.?



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


_______________________________________________
Post Messages to: ***@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/7ebb73f6-a3c4-a882-7469-***@taconic.net
** 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.
Ted Roche
2018-05-31 13:34:31 UTC
Permalink
On Tue, May 29, 2018 at 1:04 PM, Stephen Russell <***@gmail.com> wrote:
> Who has anything like a disk drive on a laptop today?
>

Pretty sure everyone has something "like" a disk drive -- isn't that
what the D in SSD and HDD stand for?

Even my Chromebook and Android phone have something "like" a disk drive.

We're still toting around workstations with one and TWO
rotating-magnetic-media (shades-of-shugart!) hard disk drives.

--
Ted Roche
Ted Roche & Associates, LLC
http://www.tedroche.com

_______________________________________________
Post Messages to: ***@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/CACW6n4uvNGyfCFoRmBQbwmU-T7Ze89ZjskBq=***@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.
Stephen Russell
2018-05-31 14:48:06 UTC
Permalink
In my mind was implying a DVD & Floppy Disk and not internal system
drive(s).

On Thu, May 31, 2018 at 8:34 AM, Ted Roche <***@gmail.com> wrote:

> On Tue, May 29, 2018 at 1:04 PM, Stephen Russell <***@gmail.com>
> wrote:
> > Who has anything like a disk drive on a laptop today?
> >
>
> Pretty sure everyone has something "like" a disk drive -- isn't that
> what the D in SSD and HDD stand for?
>
> Even my Chromebook and Android phone have something "like" a disk drive.
>
> We're still toting around workstations with one and TWO
> rotating-magnetic-media (shades-of-shugart!) hard disk drives.
>
> --
> Ted Roche
> Ted Roche & Associates, LLC
> http://www.tedroche.com
>
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@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/CAJidMYJsE23wu8BCwCPG7s9z1=***@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.
Gene Wirchenko
2018-05-31 02:03:58 UTC
Permalink
At 12:37 2018-05-21, Vince Teachout <***@taconic.net> wrote:
>On 05/20/18 3:31 PM, Ted Roche wrote:
>>On Sun, May 20, 2018 at 1:39 PM, Gene Wirchenko <***@telus.net> wrote:
>>
>>> thedate=date(9999,12,31) && Handle this extreme case.
>>And that, kids, is why we call it "The Y10K crisis..."
>
>I looking forward to all the $$$$ I'm going to make when people call
>me in from retirement to fix all their old VFP programs before
>midnight 9999! Can we say "Gouging rates?"

"Gouging rates!"

Yup!

Now, you say it.

>nb: Don't lose vfp install disk before then!

Is there any version of VFP that handles dates after
9999? There was an early -- the first? -- version of dBASE III Plus
that handled dates with years up to 32767.

Sincerely,

Gene Wirchenko


_______________________________________________
Post Messages to: ***@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/***@mtlp000086
** 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.
Loading...