Index
2018-05-08 08:07Richard Kaye : Fun with date calculations in VFP
2018-05-08 08:12Dave Crozier : RE: Fun with date calculations in VFP
2018-05-08 08:14Ted Roche : Re: Fun with date calculations in VFP
2018-05-08 08:27Richard Kaye : RE: Fun with date calculations in VFP
2018-05-08 08:28Dave Crozier : RE: Fun with date calculations in VFP
2018-05-08 08:30Richard Kaye : RE: Fun with date calculations in VFP
2018-05-08 08:43Stephen Russell : Re: Fun with date calculations in VFP
2018-05-08 09:13Ted Roche : Re: Fun with date calculations in VFP
2018-05-08 10:11Ted Roche : Re: Fun with date calculations in VFP
2018-05-08 10:23Richard Kaye : RE: Fun with date calculations in VFP
Back to top
Fun with date calculations in VFP

Author: Richard Kaye

Posted: 2018-05-08 08:07:22   Link

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.

©2018 Richard Kaye
Back to top
RE: Fun with date calculations in VFP

Author: Dave Crozier

Posted: 2018-05-08 08:12:01   Link

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","YYYY") && 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/18725B8CD2D5D247873A2BAF401D4AB2BEC935DD@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.

©2018 Dave Crozier
Back to top
Re: Fun with date calculations in VFP

Author: Ted Roche

Posted: 2018-05-08 08:14:53   Link

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 <rkaye@invaluable.com> 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.

©2018 Ted Roche
Back to top
RE: Fun with date calculations in VFP

Author: Richard Kaye

Posted: 2018-05-08 08:27:16   Link

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 <profoxtech-bounces@leafe.com> On Behalf Of Ted Roche

Sent: Tuesday, May 08, 2018 9:15 AM

To: profoxtech@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 <rkaye@invaluable.com> 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.

©2018 Richard Kaye
Back to top
RE: Fun with date calculations in VFP

Author: Dave Crozier

Posted: 2018-05-08 08:28:46   Link

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","YYYY") && 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 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/18725B8CD2D5D247873A2BAF401D4AB2BEC935DD@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.

_______________________________________________

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/18725B8CD2D5D247873A2BAF401D4AB2BEC9369B@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.

©2018 Dave Crozier
Back to top
RE: Fun with date calculations in VFP

Author: Richard Kaye

Posted: 2018-05-08 08:30:43   Link

I was just looking at your code and noticed the bit at the end seemed to have something missing.

©2018 Richard Kaye
Back to top
Re: Fun with date calculations in VFP

Author: Stephen Russell

Posted: 2018-05-08 08:43:13   Link

I found a millisecond approach a while back that hasn't given us any issues

yet

604800000 milliseconds in a week is the fact I base the code on.

var date:Date = new Date(YYYY, MM, DD);

Datetime lastyear = date.setMilliseconds(date.milliseconds - 604800000 * 52);

On Tue, May 8, 2018 at 8:07 AM, Richard Kaye <rkaye@invaluable.com> 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.

©2018 Stephen Russell
Back to top
Re: Fun with date calculations in VFP

Author: Ted Roche

Posted: 2018-05-08 09:13:18   Link

On Tue, May 8, 2018 at 9:14 AM, Ted Roche <tedroche@gmail.com> 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=v3N2ZCnatTPn2tJDvMDigxbxORPE8xiurg@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.

©2018 Ted Roche
Back to top
Re: Fun with date calculations in VFP

Author: Ted Roche

Posted: 2018-05-08 10:11:38   Link

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+ZkTHDEw@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.

©2018 Ted Roche
Back to top
RE: Fun with date calculations in VFP

Author: Richard Kaye

Posted: 2018-05-08 10:23:35   Link

Another guy that fixes his typos the 2nd time...

©2018 Richard Kaye