• does exist revese function of week( dData )

    From Marco Boschi@21:1/5 to All on Fri Jan 21 07:30:27 2022
    This function must returns the first day of te week passed as parameter
    many thanks

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dlzc@21:1/5 to Marco Boschi on Fri Jan 21 10:19:32 2022
    On Friday, January 21, 2022 at 8:30:28 AM UTC-7, Marco Boschi wrote:
    This function must returns the first day of te week passed as parameter
    many thanks

    As stated, this function will do it.

    function FirstDayOfWeek( dData )
    return 1

    But you probably meant
    function DateOfFirstDayOfWeek( dData )
    return dData - dow(dData) + 1

    David A. Smith

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marco Boschi@21:1/5 to All on Sat Jan 22 07:46:34 2022
    Il giorno venerdì 21 gennaio 2022 alle 19:19:33 UTC+1 dlzc ha scritto:
    On Friday, January 21, 2022 at 8:30:28 AM UTC-7, Marco Boschi wrote:
    This function must returns the first day of te week passed as parameter many thanks
    As stated, this function will do it.

    function FirstDayOfWeek( dData )
    return 1

    But you probably meant
    function DateOfFirstDayOfWeek( dData )
    return dData - dow(dData) + 1

    David A. Smith
    If I run this little program I obtain the list below

    FUNCTION MAIN()
    LOCAL iday
    LOCAL nWeek
    LOCAL cDay
    iDay := DATE()
    DO WHILE .T.
    nDayOfWeek := DOW( iDay )
    nWeek := week( iDay )
    cDay := cdow( iDay )
    ? iDay , nDayOfWeek , PADR( cDay , 20 ) , nWeek
    iDay --
    inkey(0)

    ENDDO

    01/22/22 7 Saturday 3
    01/21/22 6 Friday 3
    01/20/22 5 Thursday 3
    01/19/22 4 Wednesday 3
    01/18/22 3 Tuesday 3
    01/17/22 2 Monday 3
    01/16/22 1 Sunday 3
    01/15/22 7 Saturday 2
    01/14/22 6 Friday 2
    01/13/22 5 Thursday 2
    01/12/22 4 Wednesday 2
    01/11/22 3 Tuesday 2
    01/10/22 2 Monday 2
    01/09/22 1 Sunday 2
    01/08/22 7 Saturday 1
    01/07/22 6 Friday 1
    01/06/22 5 Thursday 1
    01/05/22 4 Wednesday 1
    01/04/22 3 Tuesday 1
    01/03/22 2 Monday 1
    01/02/22 1 Sunday 1
    01/01/22 7 Saturday 52


    Today is Jaunary 22 2022 And is Saturday week 3

    I need a function that returns Hanuary 16 2022 if I pass 3

    01/22/22 7 Saturday 3 last day of 3^ week
    01/21/22 6 Friday 3
    01/20/22 5 Thursday 3
    01/19/22 4 Wednesday 3
    01/18/22 3 Tuesday 3
    01/17/22 2 Monday 3
    01/16/22 1 Sunday 3 first day of 3^ week


    ? dMondayOfWeek( 3 )
    result 01/16/22

    I thought it existed I create it thanks

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dlzc@21:1/5 to Marco Boschi on Mon Jan 24 07:43:38 2022
    On Saturday, January 22, 2022 at 8:46:36 AM UTC-7, Marco Boschi wrote:
    Il giorno venerdì 21 gennaio 2022 alle 19:19:33 UTC+1 dlzc ha scritto:
    On Friday, January 21, 2022 at 8:30:28 AM UTC-7, Marco Boschi wrote:
    This function must returns the first day of te week passed as parameter many thanks

    I'd use DOY(dData) and WEEK(dData) to back into your answer. You just want to pass the week number, but not the year, is that correct? And you always want to return Monday, not Sunday?

    function DateOfWeekThisYear( WeekNumber )
    local nThisWeek := WEEK( date() )
    local nThisDay := DOY( date() )
    local nDOW := DOW( date() )
    local nReturn := nThisDay + ( WeekNumber - nThisWeek ) * 7 - (nDOW + 2)
    return BOY( date() ) + nReturn

    Clearly not tested. Also no limits checks (53 weeks in a year for example).

    David A. Smith

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