• Re: Date() + one year

    From Enrico Maria Giordano@21:1/5 to All on Mon Oct 31 15:50:56 2022
    Il 31/10/2022 15:32, Otto Haldi ha scritto:

    Hello,
    What is the easiest way to add a year to a date?
    If I do Date()+365, I will have an error with leap years.

    Something like

    Date() + 365 + IF( IsLeap( Year( Date() ) ), 1, 0 )

    --
    Enrico Maria Giordano

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Otto Haldi@21:1/5 to All on Mon Oct 31 07:32:17 2022
    Hello,
    What is the easiest way to add a year to a date?
    If I do Date()+365, I will have an error with leap years.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dlzc@21:1/5 to otto.ha...@gmail.com on Mon Oct 31 08:58:09 2022
    On Monday, October 31, 2022 at 7:32:19 AM UTC-7, otto.ha...@gmail.com wrote:
    Hello,
    What is the easiest way to add a year to a date?
    If I do Date()+365, I will have an error with leap years.

    You just need to increment the year. Enrico's method fails if "next year" is a leap year and the date sought is after February. This is sensitive to the date format you have set...

    dThisOne := date()
    dThatOne := CTOD( str( month( dThisOne )) + "-" + ;
    str(day( dThisOne )) + "-" +;
    str(year( dThisOne + 1 )) )

    Maybe something safer derived from Clipper Tools using STOD and PADLEFT...

    dThisOne := date()
    dThatOne := STOD( PADLEFT( str( year( dThisOne + 1 )), "0") +;
    PADLEFT(str( month( dThisOne )), "0") +;
    PADLEFT(str( day( dThisOne )), "0") );

    Coded in my head, not tried.

    David A. Smith

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Enrico Maria Giordano@21:1/5 to All on Mon Oct 31 18:47:59 2022
    Il 31/10/2022 16:58, dlzc ha scritto:

    Enrico's method fails if "next year" is a leap year and the date sought is after February.

    Ops, you are right!

    --
    Enrico Maria Giordano

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rainer Berning@21:1/5 to All on Mon Oct 31 19:58:30 2022
    Am 31.10.2022 um 18:47 schrieb Enrico Maria Giordano:
    Il 31/10/2022 16:58, dlzc ha scritto:

    Enrico's method fails if "next year" is a leap year and the date sought is after February.

    Ops, you are right!


    Use function AddMonth from xHarbour.

    nDate := AddMonth(Date(), 12)

    R. Berning

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Otto Haldi@21:1/5 to All on Tue Nov 1 14:03:55 2022
    Thanks so much that fixed the problem, you help is appreciated
    Otto

    Le 31/10/2022 à 19:58, Rainer Berning a écrit :
    Am 31.10.2022 um 18:47 schrieb Enrico Maria Giordano:
    Il 31/10/2022 16:58, dlzc ha scritto:

    Enrico's method fails if "next year" is a leap year and the date
    sought is after February.

    Ops, you are right!


    Use function AddMonth from xHarbour.

    nDate := AddMonth(Date(), 12)

    R. Berning



    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From timepro timesheet@21:1/5 to Otto Haldi on Tue Nov 1 07:16:55 2022
    On Tuesday, November 1, 2022 at 6:33:57 PM UTC+5:30, Otto Haldi wrote:
    Thanks so much that fixed the problem, you help is appreciated
    Otto
    Le 31/10/2022 à 19:58, Rainer Berning a écrit :
    Am 31.10.2022 um 18:47 schrieb Enrico Maria Giordano:
    Il 31/10/2022 16:58, dlzc ha scritto:

    Enrico's method fails if "next year" is a leap year and the date
    sought is after February.

    Ops, you are right!


    Use function AddMonth from xHarbour.

    nDate := AddMonth(Date(), 12)

    R. Berning


    hi:

    i have this simple method:

    if (year(yourdate+nnn))/4=int((year(yourdate+nnn))/4)
    'this is leap year'
    ...
    ...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ingo Steinbuechel@21:1/5 to timepro timesheet on Tue Nov 1 17:36:36 2022
    Hi,

    "timepro timesheet" <timecosting@gmail.com> schrieb:

    i have this simple method:

    if (year(yourdate+nnn))/4=int((year(yourdate+nnn))/4)
    'this is leap year'

    this is not correct. Look at the definition of a leap year [1].

    Regards Ingo

    [1] https://en.wikipedia.org/wiki/Leap_year#Algorithm

    --
    Threema - Sicherer und privater Messenger: https://threema.ch/de
    Meine Threema-ID: https://threema.id/ZV9BWDXK
    Warum Threema? https://warumthreema.de/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From timepro timesheet@21:1/5 to Ingo Steinbuechel on Tue Nov 1 10:07:25 2022
    On Tuesday, November 1, 2022 at 10:07:06 PM UTC+5:30, Ingo Steinbuechel wrote:
    Hi,

    "timepro timesheet" <timec...@gmail.com> schrieb:
    i have this simple method:

    if (year(yourdate+nnn))/4=int((year(yourdate+nnn))/4)
    'this is leap year'
    this is not correct. Look at the definition of a leap year [1].

    Regards Ingo

    [1] https://en.wikipedia.org/wiki/Leap_year#Algorithm

    --
    Threema - Sicherer und privater Messenger: https://threema.ch/de
    Meine Threema-ID: https://threema.id/ZV9BWDXK
    Warum Threema? https://warumthreema.de/
    ingo:

    by algorithm/mathematically...you are right...
    (2100 can be divided by 4, but isn't a leap year)
    but does anyone contemplate (while) coding for year 2100 onward...(the 'next century' leap year should be 2400).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Enrico Maria Giordano@21:1/5 to All on Tue Nov 1 18:46:19 2022
    Il 01/11/2022 18:07, timepro timesheet ha scritto:

    but does anyone contemplate (while) coding for year 2100 onward...

    Of course! :-)

    --
    Enrico Maria Giordano

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dlzc@21:1/5 to Rainer Berning on Thu Nov 3 11:56:58 2022
    On Monday, October 31, 2022 at 11:58:33 AM UTC-7, Rainer Berning wrote:
    Am 31.10.2022 um 18:47 schrieb Enrico Maria Giordano:
    Il 31/10/2022 16:58, dlzc ha scritto:

    Enrico's method fails if "next year" is a leap year and the date sought is after February.

    Ops, you are right!

    Use function AddMonth from xHarbour.

    nDate := AddMonth(Date(), 12)

    Elegant. According to Clipper Tools, could be:
    nDate := AddMonth( , 12) (or maybe just ->AddMonth(12) )
    ... since it says it defaults to system date

    David A. Smith

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)