1D add to a date

Soloper
Member Posts: 102
Hi all;
I want to insert a journal line into the Journal Line Table. For the posting date field, I want to calculate a date than insert this new date as posting date. The question is this; how to add just a day to a date? Please follow the following sample
FirstDate = myDateVariable
NewDate = myDateVariable + 1D
I want to do something like this but this code doesnt work. FirstDate, NewDate and myDateVariable is DATE.
I tried also followig example;
JournalLine."Posting Date":= "Posting Date" + 1D;
If I try to compile; It says "There is an error in a constant" and locate the cursor on the beginning of 1D.
What should I do?
Thanks.
I want to insert a journal line into the Journal Line Table. For the posting date field, I want to calculate a date than insert this new date as posting date. The question is this; how to add just a day to a date? Please follow the following sample

FirstDate = myDateVariable
NewDate = myDateVariable + 1D
I want to do something like this but this code doesnt work. FirstDate, NewDate and myDateVariable is DATE.
I tried also followig example;
JournalLine."Posting Date":= "Posting Date" + 1D;
If I try to compile; It says "There is an error in a constant" and locate the cursor on the beginning of 1D.
What should I do?
Thanks.
0
Answers
-
Try this.
FirstDate = myDateVariable NewDate = myDateVariable + 1;
0 -
Hi,
1D means DATE type constant. You can substract two dates (date-date = Integer), but you cannot add two dates. You can add integer to date instead.
If by typing 1D you meant to use DateFormula constant then you should use CALCDATE function, as DateFormulas can only be used with CALCDATE
To sum up - you have two options:
1. NewDate := myDateVariable + 1 ; //not 1D
2. NewDate := CALCDATE('1D',myDateVariable);
Regards,
SlawekSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
Thanks so much for the replies.
By the way, I want to find the NEXT WEEK DAY.
If the calculated days by the formula are Saturday or Sunday I want function to return MONDAY.
Is that possible?
Thanks again.0 -
No, it is not possible with one DateFormula.
You need to use Date virtual table, or use at least 2 date formulas and some logic, or play with Company Calendar (codeunit 7600 Calendar Management functions).
Regards,
SlawekSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
Soloper wrote:Thanks so much for the replies.
By the way, I want to find the NEXT WEEK DAY.
If the calculated days by the formula are Saturday or Sunday I want function to return MONDAY.
Is that possible?
Thanks again.
Solved.
WeekDayNumber:=DATE2DWY(PostingDate,1); //Getting the day number
CASE WeekDayNumber OF // In case of the Week Day Number, adding the days to find next week day
1,2,3,4,5:PostingDate:=CALCDATE('1D',Rec."Posting Date");
6:PostingDate:=CALCDATE('3D',Rec."Posting Date");
7:PostingDate:=CALCDATE('2D',Rec."Posting Date");
END;0 -
WeekDayNumber:=DATE2DWY(PostingDate,1); //Getting the day number
CASE WeekDayNumber OF // In case of the Week Day Number, adding the days to find next week day
1,2,3,4,5:PostingDate:=CALCDATE('1D',Rec."Posting Date");
6:PostingDate:=CALCDATE('3D',Rec."Posting Date");
7:PostingDate:=CALCDATE('2D',Rec."Posting Date");
END;
I think you need to rethink your solution...
SlawekSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
what about this:
PostingDate:=CALCDATE('<1D>',Rec."Posting Date") while DATE2DWY(PostingDate,1) in [6,7] do PostingDate:=CALCDATE('<1D>',PostingDate)
do not forget to use <> around the date formula, else it will not work for oher languages...0 -
Soloper wrote:@Slawek; why should I do that?
. Kine's solution will work, your not
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
What kind of message is this? Tested and works fine. I just wonder if there is a short and more practical way to do that.
Will you give a usefull info?
As I wrote before, kine's solution is shoter and more practical than my way. But It doesnt work for me. Explanation is in previous messages.0 -
WeekDayNumber:=DATE2DWY(PostingDate,1); //Getting the day number CASE WeekDayNumber OF // In case of the Week Day Number, adding the days to find next week day 1,2,3,4,5:PostingDate:=CALCDATE('1D',Rec."Posting Date"); 6:PostingDate:=CALCDATE('3D',Rec."Posting Date"); 7:PostingDate:=CALCDATE('2D',Rec."Posting Date"); END;
In the DATE2DWY function, Monday Equals 1.
So in your coding:
- when it is friday (5), it will not return the next working day, but saturday ...
- when is is saturday (6), it will not return the next working day (monday, + 2 days), but tuesday (+3 days)
- when it is sunday (7), it will not return the next working day (monday, + 1 days), but tuesday (+2 days)
Make any sense?
Your first case should be 1,2,3,4,7, the second should be 5 and the third should be 6. But the shorter option provided in the topic should work also0 -
Shedman wrote:Your first case should be 1,2,3,4,7, the second should be 5 and the third should be 6.
Unless your working days include Saturday but not Monday
SlawekSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
Thanks ara3n, Slawek, Kine and Shedman.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