Skip to main content
Solved

Display First Date of Last Week on Report Designer

  • September 5, 2023
  • 6 replies
  • 265 views

Forum|alt.badge.img

Hi,

We would like acumatica to display the first date of a week. For instance: Today it should show 08/28/2023. How can we achieve this?

We tried : DateAdd(Today(),'w',-3) and it displays Tuesday’s Date 08/29/23 and not 08/28/23.

What would be the best way to do this? I have this formula working in SQL :DATEADD(WEEK,DATEDIFF(WEEK,0,GETDATE())-1,0) but cannot figure out how to replicate in acumatica. 

 

@lauraj46 - Hi Laura, could you please help when you have a chance?

Best answer by lauraj46

Hi @kanupindi ,

There seem to be some idiosyncracies with the date function in report designer.  You can use CDate to cast 1/1/1900 as a date, but I had to adjust the first date forward to 5/7/1900 to get the correct date as an end result.  Not sure why it should be 5/7/1900, but this formula does seem to work:

=DateAdd(CDate('5/7/1900'), 'w', DateDiff('w', CDate('1/1/1900'), CDate(Today()))-1)

A different approach is to build the formula based on the day of the week.  The idea is to subtract a certain number of days based on the day of the week.

Beware though.  In my experiments the DayOfWeek function operates differently in a GI vs the Report Designer.  In a GI the DayOfWeek function returns 1-7 beginning with Sunday.  In the Report Designer, the DayOfWeek function appears to return 0-6 beginning with Monday.  

In the Report Designer, I was able to get the correct behavior using this formula:

=IIf(DayOfWeek(Today())=0, DateAdd(Today(), 'd', -13), DateAdd(Today(), 'd', -1*DayOfWeek(Today())-6))

Hope that helps!

Laura

 

View original
Did this topic help you find an answer to your question?

6 replies

lauraj46
Captain II
Forum|alt.badge.img+8
  • Captain II
  • 568 replies
  • September 5, 2023

Hi @kanupindi ,

Try this formula:

=DateAdd('1/1/1900', 'w', DateDiff('w', '1/1/1900', Today())-1)

Laura

 


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 63 replies
  • September 5, 2023

Hi @lauraj46, thank you for your swift response as always! I tried this on the GI and seemed to work. I still need to check the report designer as well. With this formula, would the dates change dynamically?


lauraj46
Captain II
Forum|alt.badge.img+8
  • Captain II
  • 568 replies
  • September 5, 2023

Hi @kanupindi ,

Glad that worked!  It will change dynamically based on the current date (Today() ).

Laura


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 63 replies
  • September 5, 2023

Hey @lauraj46 , it worked on the GI but not on the report writer/ report designer. We get the below error, is there a different formula that we can use on the report writer? thank you!

 

 


lauraj46
Captain II
Forum|alt.badge.img+8
  • Captain II
  • 568 replies
  • Answer
  • September 6, 2023

Hi @kanupindi ,

There seem to be some idiosyncracies with the date function in report designer.  You can use CDate to cast 1/1/1900 as a date, but I had to adjust the first date forward to 5/7/1900 to get the correct date as an end result.  Not sure why it should be 5/7/1900, but this formula does seem to work:

=DateAdd(CDate('5/7/1900'), 'w', DateDiff('w', CDate('1/1/1900'), CDate(Today()))-1)

A different approach is to build the formula based on the day of the week.  The idea is to subtract a certain number of days based on the day of the week.

Beware though.  In my experiments the DayOfWeek function operates differently in a GI vs the Report Designer.  In a GI the DayOfWeek function returns 1-7 beginning with Sunday.  In the Report Designer, the DayOfWeek function appears to return 0-6 beginning with Monday.  

In the Report Designer, I was able to get the correct behavior using this formula:

=IIf(DayOfWeek(Today())=0, DateAdd(Today(), 'd', -13), DateAdd(Today(), 'd', -1*DayOfWeek(Today())-6))

Hope that helps!

Laura

 


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 63 replies
  • September 6, 2023

Hi @lauraj46, thank you very much! That worked!! Have a great day! 😊


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings