How to display the start date and end date of previous weeks on date prompts by default.

Hello,

Good evening!
Could you please tell me how to display the start date and end date of previous weeks on date prompts by default. I am trying to fix this but still its failing. Thanks in advance.

Thanks & Regards,
Sai

Comments

  • edited March 26

    The code below gets the first and last day of the previous week:

    First day:
    BirtDateTime.firstDayOfWeek(BirtDateTime.addWeek(BirtDateTime.today(), -1))

    Last day:
    BirtDateTime.addDay(BirtDateTime.firstDayOfWeek(BirtDateTime.addWeek(BirtDateTime.today(), -1)), 6)

    Make sure the expression type for the default parameter value field is set to "fx" (JavaScript).

    Jeff F.
    Customer Support Engineer I
    OpenText
  • Hello Jeff,

    Thanks for the logic. It was working good. But I am unable to understand the logic in First day and last day. Could you please explain briefly. Thanks in advance.

    Thanks & Regards,
    Sai
  • The outer method call, BirtDateTime.firstDayOfWeek(date), returns the date for the Sunday immediately preceding the date passed in as the argument to the method. So if you give the method a date for a Monday, it will subtract one day and return that date. For a Tuesday, it will subtract two days, etc. If the date argument corresponds to a Sunday, the firstDayOfWeek method just returns that same date.

    In the formula for the first day, the date argument is another method, BirtDateTime.addWeek(date). It also takes a date argument. It shifts the date by adding or subtracting a specified number of weeks. In this case, the arguments are BirtDateTime.today() and -1. That means the current date is being shifted -1 weeks, or going backwards one week.

    To summarize: start with the current date, go back one week, and return the date of the first day (Sunday) of that week.

    I checked and did not see a lastDayofWeek method. So to get the last day of the week, I used the same formula and added 6 days to return the date for the following Saturday.

    Jeff F.
    Customer Support Engineer I
    OpenText
  • That was so clear....Thanks Jeff!!

    Thanks & Regards,
    Sai
Sign In or Register to comment.