Am I missing something or Date.WeekOfYear() reports 53 weeks for 2016?
dim d as new date(2016, 12, 31)
dim w as integer = d.weekOfYear
w = 53 but it should be 52.
I know it calculate the weeks using Sunday as the first day of week, but even with this changes nothing due 2016-12-31 is Saturday.
WeekOfYear can be more than 52 as the first week might be short. Like what Dave said. Now which day you use to “start” the week and “define” the week number, varies from implementation to implementation.
[quote]Date: 19.06.12 00:48 (Mon, 18 Jun 2012 19:48:30 -0400)
From: Greg O’Lone
WeekOfYear is counted based on the number of days since January 1st of the year you are measuring. Thusly:
January 1-7 = Week 1
January 8-14 = Week 2
THe day of week does not affect the week of year calculation.
Greg O’Lone
Software Engineer
Real Software, Inc.[/quote]
And I agree, WeekOfYearISO should be added to the date class
I doubt the global Date class will get that love. At best it might make it Xojo.Core.Date. There is currently no WeekOfYear Property. http://developer.xojo.com/xojo-core-date It should probably make it into a Feedback request.
Are you connecting to a database? If so it likely has date functions that’ll give you what you want, e.g:
Postgres: SELECT EXTRACT(WEEK FROM TIMESTAMP ‘2016-12-31’);
Firebird: SELECT EXTRACT(WEEK FROM DATE ‘2016-12-31’) AS wkno FROM rdb$database;
MySQL: SELECT WEAKOFYEAR(‘2016-12-31’);
I imagine SQLite has it too if you do a little research