📝 Introduction
In Dynamics 365 Finance and Operations (D365FO), there are scenarios where you might need to display a date in a custom format — for reports, logs, filenames, or user messages.
X++ provides a powerful utility function, date2str()
, which allows you to convert a date
type to a formatted string
using various layout options.
This post explains how to format a date in D365FO using modern and clear X++ code.
🧩 Example: Convert Today’s Date to Custom String Format
🔎 Format Explanation:
Argument | Value | Purpose |
---|---|---|
DateDay::Digits2 | 2-digit day (e.g., 01 ) | Format day component |
DateSeparator::Hyphen | - | Separator between date parts |
DateMonth::Short | Short month name (e.g., Apr ) | Format month as short text |
DateYear::Digits4 | 4-digit year (e.g., 2025 ) | Format year component |
You can customize it easily using:
-
DateSeparator::Slash
instead ofHyphen
-
DateMonth::Digits2
for numeric month -
DateDay::Name
to include weekday
🔄 Alternate Formats
Example 1: MM/DD/YYYY
Format
Example 2: Full Date with Day Name
✅ Summary
-
Use
date2str()
to convert and format dates in D365FO. -
Customize separators, order (day/month/year), and format style.
-
Helps in consistent date presentation across reports, emails, logs, etc.
🔖 Tags
D365FO Date Format
, X++ date to string
, How to use date2str()
, Convert date in D365
, X++ formatting examples
, D365FO reports
, X++ today date
, Custom date separator X++
, AX to D365FO Date Format
0 Comments