Loading...

Some Useful Date functions in dynamics 365 F&O using X++

Some Useful Date functions in dynamics 365 F&O using X++

In Dynamics 365 Finance and Operations, date functions play a crucial role in performing various operations related to date and time manipulation within the application. These functions are used to handle and process date-related data efficiently.

These date functions are particularly useful when creating custom business logic, workflows, or reports that involve date calculations or validations. They can be used in various areas of the application, such as in X++ code, formulas, workflows, and SSRS reports.

For example, if you need to calculate the due date for an invoice by adding a specific number of days to the invoice date, you can use the dateAdd() function to achieve this efficiently.

Keep in mind that Dynamics 365 Finance and Operations may have updates and enhancements over time, so it's always a good practice to refer to the official documentation for the most up-to-date information on available date functions and their usage within the platform.

There are a lot of functions in dynamics Ax for dates. Followings are some date time functions I used extensively. Some commonly used date functions in Dynamics 365 Finance and Operations include:

1. How to get current date in dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function today() is used to get the current date from the given date in dynamics 365 finance and operations,This function returns the current date that is used by the client. 

Here i have created one runnable class DateFunctionsJob. Once you created the class , you can copy and paste the below codes as per your requirements.

internal final class DateFunctionsJob

{
   public static void main(Args _args)
   {
       Transdate dateToday ;     
dateToday = today();
info(strfmt("Date- %1",dateToday));
}
}


Output :
Date - 7/22/2023

2. How to gets the Month Number from the given date in Dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function mthofYr(mydate) is used to get the Month Number from the given date in dynamics 365 finance and operations,This function returns the Month Number that is used by the client.

public static void main(Args _args)
   {
       Transdate dateToday;   
int monthNumber;
       dateToday = today();
       monthNumber=mthofYr(dateToday);
       info(strfmt("Month Number - %1",monthNumber));    
}


Output :
Month Number- 7

3. How to gets the Month Name from the given date in Dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function mthname(mthofYr(mydate)) is used to get the Month Name from the given date in dynamics 365 finance and operations,This function returns the Month Name that is used by the client.

public static void main(Args _args)
   {
       Transdate dateToday;  
str monthName ;
dateToday = today();
       monthName = mthname(mthofYr(dateToday));    
       info(strfmt("Month Name - %1",monthName));     
}


Output :
Month Name - July

4. How to gets the Day Number from the given date in Dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function dayOfMth() is used to get the Day Number from the given date in dynamics 365 finance and operations,This function returns the Day Number that is used by the client.
public static void main(Args _args)
   {
       Transdate dateToday;
       int dayNumber;
       dateToday = today();
       dayNumber = dayOfMth(dateToday);     
       info(strfmt("Day Number- %1",dayNumber));      
  }

Output :
Day Number - 22

5. How to gets the Day Name from the given date in Dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function dayname(dayOfMth(mydate)) is used to get the Day Name from the given date in dynamics 365 finance and operations,This function returns the Day Name that is used by the client.

public static void main(Args _args)
   {
       Transdate dateToday;
       str dayName;
dateToday = today();
       DayName = dayname(dayOfMth(dateToday));   
  info(strfmt("Day Name - %1",dayName));
}


Output :
Day Name - Saturday

6. How to get the year from the given date in Dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function year(mydate) is used to get the year from the given date in dynamics 365 finance and operations,This function returns the year that is used by the client.

public static void main(Args _args)
   {
       Transdate dateToday;   
int year ;
       dateToday = today();
       Year =year(dateToday);
       info(strfmt("Year - %1",year));   
}


Output :
Year - 2023

7. How to gets the week day number from the given date in Dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function dayOfwk(mydate) is used to get the week day number from the given date in dynamics 365 finance and operations,This function returns the week day number that is used by the client.

public static void main(Args _args)
   {
       Transdate dateToday;
       int weekDayNumber;
dateToday = today();
       weekDayNumber= dayOfwk(dateToday);   
  info(strfmt("Week Day Number - %1",weekDayNumber));
}


Output :
Week Day Number - 6

8. How to gets the day of year from the given date in Dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function dayOfyr(mydate) is used to get the day of year from the given date in dynamics 365 finance and operations,This function returns the day of year that is used by the client.

public static void main(Args _args)
   {
       Transdate dateToday;
       int dayOfYear;
dateToday = today();
       dayOfYear= dayOfyr(dateToday);   
  info(strfmt("Day of year - %1",dayOfYear));
}


Output :
Day of year - 203

9. How to get week of the year from the given date in Dynamics 365 Finance and Operations?

In Dynamics 365 Finance and Operations a date function wkofyr(mydateis used to get the week of the year from the given date in dynamics 365 finance and operations,This function returns the week of the year that is used by the client.

public static void main(Args _args)
   {
       Transdate dateToday;
       int weekOfYear;
dateToday = today();
       weekOfYear= wkofyr(dateToday);   
  info(strfmt("Week of the year - %1",weekOfYear));
}


Output :
Week of the year - 29


Conclusion

First and foremost, Dynamics 365 date functions significantly enhance the efficiency and accuracy of date-related calculations. Tasks such as adding or subtracting days, months, or years, determining the difference between two dates, or extracting specific components (e.g., day, month, year) from a date become seamless and error-free with the help of these functions. By automating these processes, organizations can save valuable time and resources, allowing their teams to focus on more strategic and value-added activities.

Tags

X++ date runtime functions - Dynamics 365 Finance and Operations
Date and Time Functions in Dynamics 365 Finance and Operations
Using the Date Function in Microsoft Dynamics 365 Finance and Operations
Date functions in dynamics 365 Finance and Operations
Date functions in dynamics 365 FO

Published on:

Learn more
D365 Snippets
D365 Snippets

Share post:

Related posts

Day 2: Connecting to Your First Data Source

Day 2: Connecting to Your First Data Source – 30 Days of Power BI What We Covered on Day 1 ...

3 months ago

🚀 Power BI for Beginners (2026): Complete Day 1 Guide to Start Your Data Analytics Career

30 Days of Power BI - Day 1 Introduction Your comprehensive journey to mastering Microsoft Power BI begins today. Transform raw data into act...

4 months ago

Power BI Pro: 2-Month Weekend Corporate Mastery Program

  Buy [email protected] മലയാളത്തിൽ Power BI പഠിക്കൂ – GCC ജോലിക്കാർക്കായി Special Training Program Career Upgrade ചെയ്യാൻ ആഗ്രഹിക്കുന്ന GCC...

8 months ago

Shahid - Bcom Student

 

8 months ago

Power BI Recorded Session

  Buy [email protected] മലയാളത്തിൽ Power BI പഠിക്കൂ – GCC ജോലിക്കാർക്കായി Special Training Program Career Upgrade ചെയ്യാൻ ആഗ്രഹിക്കുന്ന GCC ...

8 months ago

One to One (Personalized Sessions)

  Buy [email protected] മലയാളത്തിൽ Power BI പഠിക്കൂ – GCC ജോലിക്കാർക്കായി Special Training Program Career Upgrade ചെയ്യാൻ ആഗ്രഹിക്കുന്ന GCC...

8 months ago

30 Days Power BI Crash Course

  Buy [email protected] മലയാളത്തിൽ Power BI പഠിക്കൂ – GCC ജോലിക്കാർക്കായി Special Training Program Career Upgrade ചെയ്യാൻ ആഗ്രഹിക്കുന്ന GCC...

8 months ago

10 Days Power BI Crash Course

 🌟 മലയാളത്തിൽ Power BI പഠിക്കൂ – GCC ജോലിക്കാർക്കായി Special Training Program Career Upgrade ചെയ്യാൻ ആഗ്രഹിക്കുന്ന GCC പ്രൊഫഷണലുകൾക്കായു...

8 months ago

Free Power BI Starter Kit (PBIX + Excel + Roadmap) – Download & Start in 30 Minutes

If you’ve always wanted to learn Power BI but didn’t know where to start, this Free Power BI Starter Kit is the perfect first step. Whether yo...

8 months ago

How to Connect and Clean Excel Data in Power BI Desktop: A Beginner’s Guide

 Hello learners, In this tutorial, I am going to explain how to connect your Excel file into Power BI Desktop. In the previous videos, I...

1 year ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy