AugForums.com

An Acumatica User Group

  • Free
    • Start Here
    • Rolodex
    • Podcast
    • Blog
    • Forums
  • Paid
    • AugSQL
    • GI Course
    • GI Library
    • Consulting
  • Register
Acumatica Forums

By using this website, you agree to our Terms of Use (click here)

Forums
AUG Forums
Acumatica Generic I...
Show week in year f...
 
Notifications
Clear all

Questions Show week in year for a date

 
Acumatica Generic Inquiries & Pivot Tables
Last Post by Tim Rodman 2 years ago
7 Posts
5 Users
3 Reactions
5,104 Views
RSS
VJW
Posts: 51
 VJW
Topic starter
August 30, 2018 6:41 am
(@vjw)
Trusted Member
Joined: 6 years ago

Hi

Hoping someone can help me in this. We have a generic inquiry where we want a column in the result grid to show the week in the year for the date fetched from the SOOrder.OrderDate field. I've understood that DATEPART in SQL would get the desired result, but this is not available in generic inquiries. Any idea of how I could achieve this?


6 Replies
MichaelHansen
Posts: 149
 MichaelHansen
August 30, 2018 11:05 am
(@michaelhansen)
Estimable Member
Joined: 6 years ago

I have not tried this, but couldn't you use SOORder.OrderDate - January 1, 2018 to get the number of days, divide by 7 and round up? I think this would output an integer value for the week you're in. Of course you'd have to maintain the "2018" date field unless you did something where you pulled the year of the SOOrder.OrderDate and then applied it to the Jan 1 date field, but I'm not quite sure how to do that.


Reply
VJW
Posts: 51
 VJW
Topic starter
August 31, 2018 3:44 am
(@vjw)
Trusted Member
Joined: 6 years ago

Thanks for the input! Based on this I got an idea that seems to work. Need to verify a bit, but wanted to share it:

=Ceiling( DateDiff( 's', '1.1.'+CStr( Year([SOOrder.OrderDate] ) ), [SOOrder.OrderDate])/86400.0/7 )

I needed to take the difference in seconds and then set that to weeks by dividing by 7. This way I got it in decimal format and could then use Ceiling to get the correct week. For example 10th of January was first set to week 1(9/7=1.29= 1 in integer value), but with this it is set to week 2 which is correct.


Reply
MichaelHansen
Posts: 149
 MichaelHansen
August 31, 2018 10:17 am
(@michaelhansen)
Estimable Member
Joined: 6 years ago

That looks solid to me. I'd not tried concatenating the year on to a date so it's good to see a successful implementation of it. Thanks for sharing your solution!

 

Using your formula and modifying it: =Ceiling( DateDiff( 'w', '1.1.'+CStr( Year([SOOrder.OrderDate] ) ), [SOOrder.OrderDate]))+1
Note the "+1" at the end. The week difference only seems to return WHOLE weeks between the dates, so on one of my SO's with Date 1/11/18 it returns a "1". So I incremented the formula and the math straightened out. 


Reply
Tim Rodman reacted
Leanne Barker
Posts: 30
 Leanne Barker
May 26, 2020 8:58 am
(@myobadvanced)
Trusted Member
Joined: 6 years ago

Hi

So in my case the week number of the year starts on the first Monday of the year and not necessarily from 1 Jan which may fall on a Wednesday.

Here is my notes:

Depends on when first Monday of year
DayofWeek will give a 1 for Sunday, 2 for Monday etc
Check if 1 Jan is a Sunday then use date 2 Jan else take the Dateadd days of (-DayofWeekResult+2) days to get the first Monday from 1 Jan
That then gets the date of the first Monday, works out weeks between date and that Monday date and adds 1 to get the right week number for the Year

=Ceiling(
DateDiff( 'w',
Iif(DayOfWeek( CDate(Cstr( Year([PMTran.Date]))+'-01-01'))=1,CDate(Cstr( Year([PMTran.Date]))+'-01-02'),DateAdd(CDate(Cstr( Year([PMTran.Date]))+'-01-01'),'d',-DayOfWeek( CDate(Cstr( Year([PMTran.Date]))+'-01-01'))+2))
, CDate([PMTran.Date])))
+1

 

It seems that your 1 Jan is '1.1' but ours in Australia is like SQL yyyy-mm-dd so feel free to amend my above to suit your dates in US databases.


Reply
Tim Rodman reacted
Chris M
Posts: 3
 Chris M
February 3, 2023 10:17 pm
(@mootwo)
Active Member
Joined: 4 years ago

Perhaps this could be of use? It locates Monday of the current week, then calculates the week number. Replace "Today()" with the date field of your choosing.

=Floor(DayOfYear(DateAdd(Today(),'d', 1-DayOfWeek(Today()))) / 7) + 1

 


Reply
Tim Rodman
Posts: 3193
 Tim Rodman
Admin
October 20, 2023 8:04 pm
(@timrodman)
Famed Member
Joined: 10 years ago

This isn't what you want, but you could do the following if you wanted the Week Ending date (not Week Number) for each Sales Order.

 

You would need to join to the DateInfo table like this:

image

 

Then you could add the DateInfo.WeekEnding field to the RESULTS GRID tab.


Reply
Dianne A reacted
Forum Jump:
  Previous Topic
Next Topic  
Forum Information
Recent Posts
Unread Posts
Tags
  • 12 Forums
  • 2,526 Topics
  • 10.9 K Posts
  • 16 Online
  • 2,338 Members
Our newest member: Shoaib Shafquat
Latest Post: Pick List report suddenly not splitting on Shipment
Forum Icons: Forum contains no unread posts Forum contains unread posts
Topic Icons: Not Replied Replied Active Hot Sticky Unapproved Solved Private Closed

Online Members

  • Tim Rodman Julian Schrenzel
Acumatica Forums

Terms of Use & Disclaimers :: Privacy Policy

Copyright © 2025 · AUG Forums, LLC. All rights reserved. This website is not owned, affiliated with, or endorsed by Acumatica, Inc.

‹›×

    ‹›×