{"title":"Retrieving date data in queries","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/devenv-query-retrieve-date-data/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-query-retrieve-date-data, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-query-retrieve-date-data","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Learn how to retrieve year, month, or day from date fields in query results. Discover setup steps, examples, and best practices.","date":"2025-09-30","meta":{"topic":"concept-article"},"outline":[{"level":1,"title":"Retrieving date data in queries","slug":"retrieving-date-data-in-queries","at":0,"chars":6234},{"level":2,"title":"Setting up a Date method on a query column","slug":"setting-up-a-date-method-on-a-query-column","at":172,"chars":452},{"level":2,"title":"Sample table and query","slug":"sample-table-and-query","at":624,"chars":1557},{"level":3,"title":"Sample Sales Header table","slug":"sample-sales-header-table","at":748,"chars":597},{"level":3,"title":"Sample query","slug":"sample-query","at":1345,"chars":836},{"level":2,"title":"Day method","slug":"day-method","at":2181,"chars":583},{"level":3,"title":"Example","slug":"example","at":2450,"chars":314},{"level":2,"title":"Month method","slug":"month-method","at":2764,"chars":593},{"level":3,"title":"Example - Month method","slug":"example---month-method","at":3059,"chars":298},{"level":2,"title":"Year method","slug":"year-method","at":3357,"chars":487},{"level":3,"title":"Example - Year method","slug":"example---year-method","at":3565,"chars":279},{"level":2,"title":" Working with DateTime Data Types","slug":"working-with-datetime-data-types","at":3844,"chars":1726},{"level":2,"title":"Date methods behavior on blank Date and DataTime fields","slug":"date-methods-behavior-on-blank-date-and-datatime-fields","at":5570,"chars":524},{"level":2,"title":"Related information","slug":"related-information","at":6094,"chars":140}],"text":"# Retrieving date data in queries\nYou can use a date method to retrieve only the year, month, or day from date fields in query results, instead of including the full date.\n## Setting up a Date method on a query column\nTo set up a date method on a query column, set the properties/devenv-method-property to Day, Month, and Year.\n> IMPORTANT\n> You can only use a date method on fields that have a Date or DateTime data type. Learn more about using a date method on a field that has the DateTime data type in Working with DateTime Data Types<#DateTime>.\nLearn how to set up query columns and properties in devenv-query-object.\n## Sample table and query\nThis article uses the following sample table and query to demonstrate the different date methods.\n### Sample Sales Header table\nThe following table contains data about sales orders for customers. The Order Date field has the data type of Date and the format DD-MM-YYYY, where DD is the day, MM is the month, and YYYY is the year.\nNo.|Bill-to Name|Order Date\n1000|Autohaus Meilberg KG|18-01-2019\n5000|Autohaus Meilberg KG|21-05-2019\n4000|Beef House|30-09-2017\n3000|Deerfield Graphics Company|05-04-2018\n3000|Deerfield Graphics Company|29-04-2018\n> NOTE\n> The table is a simplified subset of the data that is found in table 36 Sales Header of the CRONUS International Ltd. demonstration database.\n### Sample query\nThe following query object retrieves data from the sample Sales Header table. The query includes a totals method that counts the total number of records from the table included in the dataset.\n```al\nquery 50100 \"Sample Data Query\"\n{\n    QueryType = Normal;\n\n    elements\n    {\n        dataitem(Sales_Header; \"Sales Header\")\n        {\n            column(Bill_to_Name; \"Bill-to Name\")\n            {\n            }\n\n            column(Order_Date; \"Order Date\")\n            {\n                // Change the value of the property to Day, Month, or Year\n                Method = Day;\n            }\n\n            column(Count_)\n            {\n                Method = Count;\n            }\n        }\n    }\n}\n```\n> NOTE\n> A column that applies a date method is still part of the group unlike columns that apply an aggregate method.\n## Day method\nThe Day method retrieves the day from the date expression of a field value in the query column. The day is returned as an integer, in the range of 1 to 31, which represents the day of the month. If the day in the date expression is 0, then 1 is returned.\n### Example\nThe following table displays the resulting dataset for the sample query with the Method property of the `Order Date` column set to Day.\nBill_to_Name|Day_Order_Date|Count_\nAutohaus Meilberg KG|18|1\nAutohaus Meilberg KG|21|1\nBeef House|30|1\nDeerfield Graphics Company|5|1\nDeerfield Graphics Company|29|1\n## Month method\nThe Month method retrieves the month from the date expression of a field value in the query column. The month is returned as an integer, in the range of 1 to 12, where 1 represents January and 12 represents December. If the month in the date expression is 0, then 1 is returned.\n### Example - Month method\nThe following table displays the resulting dataset for the sample query with the Method property of the `Order Date` column set to Month.\nBill_to_Name|Month_Order_Date|Count_\nAutohaus Meilberg KG|1|1\nAutohaus Meilberg KG|5|1\nBeef House|9|1\nDeerfield Graphics Company|4|2\n## Year method\nThe Year method gets the year from the date expression of a field value in the query column. The year is returned as an integer. If the year in the date expression is 0, then 1900 is returned.\n### Example - Year method\nThe following table displays the resulting dataset for the sample query with the Method property of the `Order Date` column set to Year\nCustomer Name|Year_Order_Date|Count_\nAutohaus Meilberg KG|2019|2\nBeef House|2017|1\nDeerfield Graphics Company|2018|2\n##  Working with DateTime Data Types\nOn the SQL server, date and time values are processed using Coordinated Universal Time \\(UTC\\). If your Business Central solution uses a time zone other than UTC and the field on which you apply the date method has a data type of DateTime, then there might be a difference between the date value that is returned in the dataset for the field and the actual day, month, or year for the field in the table. This situation occurs when the corresponding UTC date for a field falls on the next day or previous day because of the time of day and the time zone of Business Central solution. The following table includes examples of DateTime values for two time zones that return days, months, and years in a dataset that differ from the values in the table.\nTime Zone|Date and Time in Business Central|Day returned by Day method|Month returned by Month method|Year returned by Year method\nPacific Time \\(UTC -8:00:00\\)|12-31-2025 17:00:00|31|12|2025\nMiddle European Time \\(UTC +1:00:00\\)|01-01-2025 00:59:00|1|1|2025\nThe differences in day, month, or year occur because when a date and time value is retrieved from the Business Central database table, it's converted from the regional settings of the Business Central solution to the UTC date and time. The day, month, or year is calculated on the SQL server, and then returned to the query dataset as an integer, which doesn't consider the regional settings of the Business Central solution.\nTo avoid this condition, you should use the date method on fields that have a Date data type instead of a DateTime data type whenever possible. You can also return the DateTime value and implement post processing for the day, month, and year as needed.\n## Date methods behavior on blank Date and DataTime fields\nThis section explains how the Day, Month, and Year methods handle blank (undefined) Date and DateTime fields. In Business Central, a blank date is represented internally as 0D. In SQL Server, a blank date is 01-01-1753 (day-month-year).\nHowever, the values that date methods return for blank fields differ by product version. The following table shows the version-specific results:\nBusiness Central version|Day|Month|Year\n26 and earlier|1|1|1753\n27 and later|0|0|0\n## Related information\ndevenv-query-object\nAggregating data in query objects<devenv-query-totals-grouping>\nproperties/devenv-method-property"}