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.
Answers
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
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,
Slawek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
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.
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,
Slawek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
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;
I think you need to rethink your solution...
Slawek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
do not forget to use <> around the date formula, else it will not work for oher languages...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
@Kine; I want to find next weekday for all days. I mean IF the date is wednesday; I want the function return Thursday.
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
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.
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 also
Slawek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03