To perform tasks such as completing transactions for a date that is not the current date, you may have to temporarily change the work date. This recipe will show you how to determine what that actual work date is as well as when and where you should use it.
Navigate to Application Menu | Set Work Date or select the date in the status bar at the bottom of Microsoft Dynamics NAV.
Input the work date in the Work Date field or select it from the calendar.
Let's get started by creating a new codeunit from Object Designer.
Then add the following code into the
OnRun
trigger of the codeunit:MESSAGE('Work Date: %1\Todays Date: %2\Current Time: %3',WORKDATE, TODAY, TIME);
To complete the task, save and close the codeunit.
On executing the codeunit, you should see a window similar to the following screenshot:
To understand WORKDATE
, we have used two more keywords in this recipe. The work date is a date internal to the NAV system. This date is returned using the WORKDATE
keyword. It can be changed at any time by the user. The next date is TODAY
; it's a keyword to retrieve the present date that provides the date from the system. In the end, we used the
TIME
keyword, which provides current time information from the system clock.
Note
It is important to understand the difference between the NAV work date and the computer system date; they should be used in specific circumstances. When performing general work in the system, you should almost always use the WORKDATE
keyword. In cases where you need to log information and the exact date or time when an action occurred, you should use TODAY
or TIME
, or CURRENTDATETIME
.
The following code can be found in the 38
, Purchase Header
table, in the UpdateCurrencyFactor()
method:
IF "Posting Date" <> 0D THEN CurrencyDate := "Posting Date" ELSE CurrencyDate := WORKDATE;
Looking at this code snippet, we can see that if a user has not provided any specific posting date, the system will assign the value WORKDATE
as the default value for the posting date.