Forum Discussion
dko71166
May 29, 2025Copper Contributor
add year month and week using just date field
I have this posting date field and I want to update yr mo and week based on posting date. I saw some suggestions online but cant make them work?
3 Replies
Sort By
- arnel_gpSteel Contributor
as suggested, remove the YR, MO, Week field from your table and instead create a Query that will calculate those 3 fields:
SELECT [Internal Number], [Document Number], [Posting Date], Year([Posting Date]) As YR, Month([Posting Date]) As MO, DatePart("ww", [Posting Date]) As Week FROM [Sales by Customer-Item-Detail];
For year and month you can use the native functions Year and Month.
For week you may get away with DatePart("ww", [Posting Date]). However, if you wish the ISO 8601 weeknumber, a custom function is needed like my function Week found in module DateCore in my repository at GitHub: VBA.Date.
As noted, don't update a table; create and run a select query.
- XPS35Iron Contributor
You should not store this type of data because it is derived data. By storing both the date and the day, month and year you run the risk of inconsistent data.
Store only the date. If you want to show the day, month or year you create a query. Use the DAY, MONTH and YEAR functions to derive the data.