IC SunsetThe developerWorks Connections platform will be sunset on December 31, 2019. On January 1, 2020, this community and its apps will no longer be available. More details available on our FAQ.
Topic
  • 9 replies
  • Latest Post - ‏2019-07-05T11:34:05Z by robberendt
Archanaa
Archanaa
7 Posts

Pinned topic same week time last year

‏2013-10-21T22:09:26Z | date

Hi,

How can I subtract 52 weeks from current date. The pupose is, I want to go back  to the same week day last year and use that date in calculations.

for ex. if today is 2013-10-21, same week day last year date will be 2012-10-22.

Any thoughts?

 

 

 

  • paulhospers
    paulhospers
    4 Posts

    Re: same week time last year

    ‏2013-10-22T15:01:26Z  

    How about

    current date - 1 year

    or

    current date - 12 months

     

  • Archanaa
    Archanaa
    7 Posts

    Re: same week time last year

    ‏2013-10-22T16:19:23Z  

    How about

    current date - 1 year

    or

    current date - 12 months

     

    This will take me back to the same date last year. I want to go back to same week day of last year.

    Let's say today's date '2013-10-22' is a tuesday in 41st week. So, I want to get a date for a Tuesday in 41st week of last year.

     

    Thanks,

  • B.Hauser
    B.Hauser
    320 Posts

    Re: same week time last year

    ‏2013-10-23T07:56:07Z  
    • Archanaa
    • ‏2013-10-22T16:19:23Z

    This will take me back to the same date last year. I want to go back to same week day of last year.

    Let's say today's date '2013-10-22' is a tuesday in 41st week. So, I want to get a date for a Tuesday in 41st week of last year.

     

    Thanks,

    You may try something like this:

    Values(Next_Day(Current_Date - 1 Year, DayName(Current_Date));

    Birgitta

     

     

  • Archanaa
    Archanaa
    7 Posts

    Re: same week time last year

    ‏2013-10-23T16:02:29Z  
    • B.Hauser
    • ‏2013-10-23T07:56:07Z

    You may try something like this:

    Values(Next_Day(Current_Date - 1 Year, DayName(Current_Date));

    Birgitta

     

     

    Yesterday I tried (Current Date -364 days). I tested it and looks like it is working. Can you think of any drawbacks in using it.

    Thank You for the replies.

     

  • B.Hauser
    B.Hauser
    320 Posts

    Re: same week time last year

    ‏2013-10-24T06:54:38Z  
    • Archanaa
    • ‏2013-10-23T16:02:29Z

    Yesterday I tried (Current Date -364 days). I tested it and looks like it is working. Can you think of any drawbacks in using it.

    Thank You for the replies.

     

    What about a leap year? Does it work correctly (I didn't test it out)

    Birgitta

    Updated on 2013-10-24T06:55:37Z at 2013-10-24T06:55:37Z by B.Hauser
  • Archanaa
    Archanaa
    7 Posts

    Re: same week time last year

    ‏2013-10-24T15:59:19Z  
    • B.Hauser
    • ‏2013-10-24T06:54:38Z

    What about a leap year? Does it work correctly (I didn't test it out)

    Birgitta

    It is working!!

    Thanks,

     

  • 66B5_Garold_Larson
    66B5_Garold_Larson
    1 Post

    Re: same week time last year

    ‏2019-07-04T19:28:31Z  
    • Archanaa
    • ‏2013-10-24T15:59:19Z

    It is working!!

    Thanks,

     

    The (Current Date -364 days) does not work for leap year.

    Birgitta, could you please supply a complete statement for

    Values(Next_Day(Current_Date - 1 Year, DayName(Current_Date));

    I have tried it in various forms and cannot get it to work.

    Thank you

  • B.Hauser
    B.Hauser
    320 Posts

    Re: same week time last year

    ‏2019-07-05T05:50:07Z  

    The (Current Date -364 days) does not work for leap year.

    Birgitta, could you please supply a complete statement for

    Values(Next_Day(Current_Date - 1 Year, DayName(Current_Date));

    I have tried it in various forms and cannot get it to work.

    Thank you

    I missed a closing quite in my example.

    The following example should work correctly:

    Values(Next_Day(Current_Date - 1 Year, DayName(Current_Date)));
    

    Birgitta

  • robberendt
    robberendt
    84 Posts

    Re: same week time last year

    ‏2019-07-05T11:34:05Z  
    • B.Hauser
    • ‏2019-07-05T05:50:07Z

    I missed a closing quite in my example.

    The following example should work correctly:

    <pre dir="ltr">Values(Next_Day(Current_Date - 1 Year, DayName(Current_Date))); </pre>

    Birgitta

    Is week number really significant? 

    For example if today's date was in the 27th week can you guarantee that the formula provided would give you the same day of the week, in the same week number, of the previous year?

     

    Let's expand Birgitta's example:  

    values week(date('2012-12-30')); -- Returns week # 53  

    Values week(Next_Day(date('2012-12-30') - 1 Year, DayName(date('2012-12-30')))); -- Returns week 1