Determining Quarter?

nverma
Member Posts: 396
Hello yall,
I have been asked to create this report and I am not sure how to get it started.
I have to write some code that will figure out what Quarter we are in based on the current date.
Our first quarter starts from April1, 2012.
I was thinking maybe it can be done using "case" statements.
Any suggestions???
I have been asked to create this report and I am not sure how to get it started.
I have to write some code that will figure out what Quarter we are in based on the current date.
Our first quarter starts from April1, 2012.
I was thinking maybe it can be done using "case" statements.
Any suggestions???
0
Answers
-
I think this should be it:
Date := Today; Month := DATE2DMY(Date,2); CASE Month OF 1..3: Message('You are in Quarter 4'); 4..6: Message('You are in Quarter 1'); 7..9: Message('You are in Quarter 2'); ELSE Message('You are in Quarter 3'); END;
0 -
From object designer, click the 'Form' button, hit F3, which should start the new form wizard. Under Table, type in 'Date', select 'tabular' and hit OK. Move all fields over and hit 'Finish'. Run the form, and see what shows up.
This is the virtual table called 'Date', and it knows about quarters. Instead of programming your own date processing code, familiarize yourself with this virtual table.0 -
I have two questions:-
I have been able to detect which quarter we are in depending on the current date. Now I have created two new variables:- QuarterBegin (date) and QuarterEnd (date).
So if the current date for instance is May 23. I want it to determine all the 'Job No.' that fall in that quarter (which would be QuarterBegin = 04/01 and QuarterEnd = 06/31).
How can I do this without providing an explicit year (or does that even matter whether I enter a year or not). I want to make a my QuarterBegin and QuarterEnd generic. So that report would work in any year.
Any suggestions?
Also, right now it gives me an error that the type of conversion is not possible (date := decimal) which i dont understand since the QuarterBegin is off type date.0 -
I'm not sure what you are referring to when you ask about not specifying the year. A date always includes a year. A date without a year is not a date.
If you know the quarter, you also know the quarter's start and end dates. Use those dates to set filters on the other table, so you can figure out the jobs between those dates.
About that error, that's a type conversion error. Somewhere you are trying to put a decimal value into a date type variable or vice versa (hard to tell without the actual error message). You need to make sure that you take care of aligning data types.
That's what programming is all about, you have to figure out the puzzle.0 -
This is the Code, I have so far. If I get rid of line QuarterBegin and QuarterEnd. I dont get the error no more.
This is the exact Error: - "The type of conversion is not possible because 1 of the operators contains an invalid type. Date := Decimal".CurrentDate := TODAY; Month := DATE2DMY(CurrentDate,2); CASE Month OF 1..3: MESSAGE('You are in Quarter 4'); 4..6: QuarterBegin := 01/04/12; QuarterEnd := 30/06/12; MESSAGE('You are in Quarter 1'); 7..9: MESSAGE('You are in Quarter 2'); ELSE MESSAGE('You are in Quarter 3'); END;
I am specifying QuarterBegin and End year to be 2012. Wouldnt that create a problem next year since my QuarterBegin and end would be in year 2013. Thats why I wanted to how to bypass this problem and somehow create a generic date, so year wont create an issue, no matter what year we are in.0 -
01/04/12 is not date, it is 01 / 04 / 12 = 0,0208333333333333
if you want to enter date, enter it as 040112D (or is it 010412D??? :whistle: )0 -
Thank you so much. That worked like a charm.
Just one last question.
How can I Make QuarterBegin and QuarterEnd generic.QuarterBegin := 010412D; QuarterEnd := 300612D;
Right now, it would only work, if the year is 2012. But I want it to work for any year.
Any suggestions?0 -
-
That makes so much sense. Thanks!!!0
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