Bug in CALCDATE?

helm
Member Posts: 46
Hello,
I'm fairly new to C/SIDE and don't know if I've made the right conclusions. I seems to me that there is a bug in CALCDATE. The code i've tried is CALCDATE('<CM-1M+1D>',WORKDATE). I'm trying to get the first date of the month that includes the current workdate. If Workdate is in February it returns 070129. If it's in April the returnvalue is 070331. Works for January and Mars though. It always withdraws 31 days. Also tried the following code for testing CALCDATE('<CM+1M>',WORKDATE). It returned for January 070228 (correct), february 070328 (wrong), Mars 070430 (correct) and April 070530 (wrong). Haven´t tried it for the rest of the year. BTW the dateformat in sweden is YYMMDD.
Am I missunderstanding something about CALCDATE or is it a bug? ](*,). If it´s a bug, does anybody know of a simple workaround?
Thanks in advance.
I'm fairly new to C/SIDE and don't know if I've made the right conclusions. I seems to me that there is a bug in CALCDATE. The code i've tried is CALCDATE('<CM-1M+1D>',WORKDATE). I'm trying to get the first date of the month that includes the current workdate. If Workdate is in February it returns 070129. If it's in April the returnvalue is 070331. Works for January and Mars though. It always withdraws 31 days. Also tried the following code for testing CALCDATE('<CM+1M>',WORKDATE). It returned for January 070228 (correct), february 070328 (wrong), Mars 070430 (correct) and April 070530 (wrong). Haven´t tried it for the rest of the year. BTW the dateformat in sweden is YYMMDD.
Am I missunderstanding something about CALCDATE or is it a bug? ](*,). If it´s a bug, does anybody know of a simple workaround?
Thanks in advance.
0
Answers
-
Your explanation is a little confused: do you want the first day of current month or the last date of current month or the last date of next month?
To be sure, I give all 3 possibilities:
datTheDate := 24042007D;
First day of current month:MESSAGE('<%1>',dmy2date(1,date2dmy(datTheDate,2),date2dmy(datTheDate,3)));
Last date of current month:datTheDate := calcdate('<+1M>',datTheDate); MESSAGE('<%1>',dmy2date(1,date2dmy(datTheDate,2),date2dmy(datTheDate,3)) - 1);
Last date of next month:datTheDate := calcdate('<+2M>',datTheDate); MESSAGE('<%1>',dmy2date(1,date2dmy(datTheDate,2),date2dmy(datTheDate,3)) - 1);
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
helm wrote:Hello,
I'm fairly new to C/SIDE and don't know if I've made the right conclusions. I seems to me that there is a bug in CALCDATE. The code i've tried is CALCDATE('<CM-1M+1D>',WORKDATE). I'm trying to get the first date of the month that includes the current workdate. If Workdate is in February it returns 070129. If it's in April the returnvalue is 070331. Works for January and Mars though. It always withdraws 31 days. Also tried the following code for testing CALCDATE('<CM+1M>',WORKDATE). It returned for January 070228 (correct), february 070328 (wrong), Mars 070430 (correct) and April 070530 (wrong). Haven´t tried it for the rest of the year. BTW the dateformat in sweden is YYMMDD.
Am I missunderstanding something about CALCDATE or is it a bug? ](*,). If it´s a bug, does anybody know of a simple workaround?
Thanks in advance.
Its not a bug, you are missing something. Try
CALCDATE('<-CM>',WORKDATE)David Singleton0 -
That's a good one, calling a code feature a bug because it doesn't do what you think it does
:bug:
0 -
I need to correct this:kriki wrote:datTheDate := 24042007D;
First day of current month:MESSAGE('<%1>',dmy2date(1,date2dmy(datTheDate,2),date2dmy(datTheDate,3)));
Last date of current month:datTheDate := calcdate('<+1M>',datTheDate); MESSAGE('<%1>',dmy2date(1,date2dmy(datTheDate,2),date2dmy(datTheDate,3)) - 1);
Last date of next month:datTheDate := calcdate('<+2M>',datTheDate); MESSAGE('<%1>',dmy2date(1,date2dmy(datTheDate,2),date2dmy(datTheDate,3)) - 1);
Correct using of CALCDATE:
First day of current month (as David wrote):datTheDate := calcdate('<-CM>',datTheDate); MESSAGE('<%1>',datTheDate);
Last date of current month:datTheDate := calcdate('<CM>',datTheDate); MESSAGE('<%1>',datTheDate);
Last date of next month:datTheDate := calcdate('<CM+1M>',datTheDate); MESSAGE('<%1>',datTheDate);
:-) It is easy. You need to know that if you do not enter +/-, + is used automatically.0 -
Correct using of CALCDATE:
First day of current month (as David wrote):
Code:
datTheDate := calcdate('<-CM>',datTheDate);
MESSAGE('<%1>',datTheDate);
Last date of current month:
Code:
datTheDate := calcdate('<CM>',datTheDate);
MESSAGE('<%1>',datTheDate);
Last date of next month:
Code:
datTheDate := calcdate('<CM+1M>',datTheDate);
MESSAGE('<%1>',datTheDate);
It is easy. You need to know that if you do not enter +/-, + is used automatically.
Thanks for all replies. I've tested the ones above and the first two worked just fine, using the workdate. (The first one was the one I wanted). But eager to learn as I am I tested all three. The last one works just fine for January and Mars. However, if workdate is in february it returns 070328, and if it's april it returns 070530. Same result (and same code) as in my previous attempt. Since my main problem is solvedit's not important, but I would like to know if it's supposed to work like this. :-s
0 -
Ok, than you can try it with <1M+CM> instead <CM+1M>. 8)0
-
Thanks, that one worked.0
-
kine wrote:...
Correct using of CALCDATE:
First day of current month (as David wrote):
[code]
Last date of next month:
[code]datTheDate := calcdate('<CM+1M>',datTheDate);
MESSAGE('<%1>',datTheDate);[/code]
Actually this is probably what Helm was thinking.
But +1m, actually finds the same date in the next month. So if you are in a month with 31 days it works, since the next month does not have 31 days, it rolls back to 28,29 or 30. But if you do this say in April, then CM give you April 30, +1m gives you May 30, where as you really want May 31, so the correct code is
CALCDATE('<1m+CM>',WORKDATE)David Singleton0 -
kine wrote:Ok, than you can try it with <1M+CM> instead <CM+1M>. 8)
Opps sorry, I obviously had this open a long time. Still I am sure my explanation helps.David Singleton0 -
Thanks David, now I don't only know that it works but why and how it works. Another thanks to Kine, who posted the first solution0
-
helm wrote:Thanks David, now I don't only know that it works but why and how it works. Another thanks to Kine, who posted the first solution
Actually when I first started in Navision (back in DOS days) I wrote a form that I used to learn CALCDATE.
I converted it to Windows some time ago to help explain CALCDATE to a client.
I have uploaded it on my site here:
http://www.go-live.us/downloads.htm
Feel free to use it for training purposes.David Singleton0 -
Thanks David. Sadly none of the links under "Understanding the CALCDATE function" worked
. Got an 404 page not found-error
0 -
helm wrote:Thanks David. Sadly none of the links under "Understanding the CALCDATE function" worked
. Got an 404 page not found-error
You were two fast, I was uploading whilst you were trying to down load.David Singleton0
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