Calculating current quarter start and end

erugalatha
Member Posts: 120
Hi,
I have a dropdown on a form that allows the user to select Monthly,Quarterly etc. I need to calculate a period depending on what is selected.
e.g. if monthly is selected then I got to calculate the period in the format:
DD MM YY - DD MMM YY
where the first DD MMM YY is the first day of the current month and the second DD MMM YY is the last day of the current month.
if quarterly is selected then I need to calculate the current 3 month quarterly period in the above format.
Anyone know a way to do this?
I have a dropdown on a form that allows the user to select Monthly,Quarterly etc. I need to calculate a period depending on what is selected.
e.g. if monthly is selected then I got to calculate the period in the format:
DD MM YY - DD MMM YY
where the first DD MMM YY is the first day of the current month and the second DD MMM YY is the last day of the current month.
if quarterly is selected then I need to calculate the current 3 month quarterly period in the above format.
Anyone know a way to do this?
0
Answers
-
CALCDATE -
<-CQ> first day of quarter
<CQ> last day of quarter
(or at least from memory it is, its something like that, you may need to play a bit.)David Singleton0 -
Correct, David.
This is from Help:CALCDATE (Date)
Calculates a new date based on a date expression and a reference date.
NewDate := CALCDATE(DateExpression [, Date])
NewDate
Data type: date
The date the system computes from the reference date and the date expression.
DateExpression
Data type: text, code or dateformula
The date expression can be any length. The system interprets the string from left to right, one subexpression at a time. The following rules describe the valid syntax of date expressions:
DateExpression =
<SubExpression>
<SubExpression>
[<Sign>] <Term>
<Sign>
+ | -
<Term>
(see below)
This is the syntax of <Term>:
<Term> =
<Number><Unit> | <Unit><Number> | <Prefix><Unit>
<Number>
Positive integer
<Unit>
D | WD | W | M | Q | Y
(D=day, WD=Weekday, W=Week, M=Month,
Q=Quarter, Y=Year)
<Prefix>
C(C=Current)0 -
Hi Guys,
I have a date and i need to know in which quarter it falls. How can this be achieved.
My Quarters are:
Q1 = April to June
Q2 =July to Sept
Q3 =Oct to Dec
Q4 = Jan to Mar
For Eg: The Ref date is 30-04-15, which is a date field of a X table.
I tried using Calcdate:
datQuarter := CALCDATE('<CQ>',RefDate);
MESSAGE('datQuarter - %1',datQuarter);
Variable :
datQuarter date (datatype)
RefDate date (datatype)
But the error i get while executing is
Microsoft Dynamics NAV Classic
You cannot base a date calculation on an undefined date.
Date: 0D
Formula: CQ
OK
0 -
Hi Guys,
I have a date and i need to know in which quarter it falls. How can this be achieved.
My Quarters are:
Q1 = April to June
Q2 =July to Sept
Q3 =Oct to Dec
Q4 = Jan to Mar
For Eg: The Ref date is 30-04-15, which is a date field of a X table.
I tried using Calcdate:
datQuarter := CALCDATE('<CQ>',RefDate);
MESSAGE('datQuarter - %1',datQuarter);
Variable :
datQuarter date (datatype)
RefDate date (datatype)
But the error i get while executing is
Microsoft Dynamics NAV Classic
You cannot base a date calculation on an undefined date.
Date: 0D
Formula: CQ
OK
0 -
Hi,
The error you get is because RefDate probably has no value.
If is HAS a value, then you can use this formula to calculate your quarter:q := (((( DATE2DMY(RefDate,2)-1) div 3) + 3) mod 4) + 1;
A little explanation:
DATE2DMY(RefDate,2) gives you the month number. Subtract 1 to get it zero-based ( numbered from 0..11 instead of 1..12 )
Then div 3 gives you a 'normal' quarter number 0, 1, 2 or 3. In normal cases you should just add 1 and be finished.
Because your first quarter is starting in April, you would like this list to be 3, 0, 1, 2
You can achieve that by using modulo 4 calculation: add 3 and then calculate mod 4
As a last step you need to translate 3, 0, 1, 2 to 4, 1, 2, 3 --> so just add 1.Jan Veenendaal1
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions