Some Useful Date functions in dynamics 365 F&O using X++
![Some Useful Date functions in dynamics 365 F&O using X++ Some Useful Date functions in dynamics 365 F&O using X++](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3adUFln1XQzkWn4ltJbPfygvQq10phX1A44WxqKpN8ajRofr1t_UDVcugvdwT0HaF9jQ5uMNn26g-7hHfN-aheVeA5-BFpLIrCAyUly9-Xt9vdv-HsW0orDNIHqV6uFiYMf0tR925X65UC5GBHJRbhUcofxgarTie72UuGrRts4xefdrT6V5rhv5Jc9c/s16000/date%20functions%20in%20dynamics%20365%20finance%20and%20operations.png)
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?
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?
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?
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?
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?
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?
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?
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?
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
Published on:
Learn moreRelated posts
D365 Sending Email with Customer Account Statement SSRS report as attachment using X++
D365 Sending Email with Customer Account Statement SSRS report as attachment using X++ custTable _custTable; &...
clicking link on info message X++ to Open form
Message::AddAction() method can be used to embed an action within a message sent to the message bar. This method supports adding a singl...
Implement Periodic Data Export from D365FO to SFTP
This blog post describes how to implement various scenarios for periodic data export from D365FO to a file and uploading it to SFTP server.
[New Feature] Financial Consolidation Template in Microsoft Dynamics 365 Finance and Operations
🚀 New Feature Online Consolidation Template! 🚀 This feature streamlines the financial consolidation process and enhances the user experience...
[New Feature] Bank Account Lifecycle Management in Microsoft Dynamics 365 Finance and Operations
🚀 New Feature: Workflow approvals for Bank master! 🚀 Microsoft has recently added a new preview feature in Microsoft Dynamics 365 Finance an...
Business Performance Analytics in Microsoft Dynamics 365 Finance and Operations: Part-2
📢 Now Time to Business Performance Analytics in Microsoft Dynamics 365! Let’s dive into the various reports available in Business Perfo...
Business Performance Analytics in Microsoft Dynamics 365 Finance and Operations: Part-1
📢 Now Time to Business Performance Analytics in Microsoft Dynamics 365! While we focus on new developments around Copilot and AI, let’s...
Dual Currency Valuation/Reporting using Global Inventory Accounting in Microsoft Dynamics 365 Finance and Operations: Part-12
📢 Part-3: Now Time to Explore Global Inventory Accounting in Microsoft Dynamics 365! 🌍 Welcome to the next part of Global inventory accounti...
Configure Reporting for Global Inventory Accounting in Microsoft Dynamics 365 Finance and Operations: Part-11
📢 Part-2: Now Time to Explore Global Inventory Accounting in Microsoft Dynamics 365! 🌍 In the next part of our Global Inventory Accounting s...
Global Inventory Accounting in Microsoft Dynamics 365 Finance and Operations: Part-10
📢 Now Time to Explore Global Inventory Accounting in Microsoft Dynamics 365! 🌍 I’m excited to dive into one of the most powerful featu...