Page 1 of 1
Week number in a Year
Posted: Sat Jul 06, 2024 7:35 pm
by miskox
Date library has this (from the online help):
Code: Select all
AddDate
ConvertDate
Date
DateUTC
Day
DayOfWeek
DayOfYear
FormatDate
Hour
Minute
Month
ParseDate
Second
Year
Maybe it would be nice to add a function to return week number in a year.
To also have a function to return working day number in a month/year (only taking into the account working days mon-fri). Holidays are special cases (maybe could be added if holidays information is stored somewhere (array?)).
Thanks.
Saso
Re: Week number in a Year
Posted: Sat Jul 06, 2024 8:11 pm
by AZJIO
https://learn.microsoft.com/en-us/windo ... ateformata
https://learn.microsoft.com/en-us/windo ... t-pictures
Code: Select all
time.systemtime
GetDateFormat_(#LOCALE_SYSTEM_DEFAULT, 0, @time, "MMMMM", @result, 16)
GetDateFormat_(#LOCALE_SYSTEM_DEFAULT, 0, @time, "ddd", @result, 16)
Re: Week number in a Year
Posted: Sat Jul 06, 2024 8:38 pm
by jacdelad
...if you are on Windows.
Otherwise, or if you don't want to use API calls, take a look into the Tipps&Tricks section. It contains at least two Date modules. Maybe they already have this built-in; if not, I'm sure the author will add it quickly.
Re: Week number in a Year
Posted: Sat Jul 06, 2024 10:46 pm
by TassyJim
Depending on what country you are in, week number is easy with what we have.
Code: Select all
weeknumber.l = (DayOfYear(Date(2024,7,7,0,0,0))+6)/7
Debug weeknumber
This will cause much eye rolling and complaints from some countries who want every week to start on Sunday (or Monday) including for week number of the year.
Working days is trickier due to it being even more political, not logical.
Assuming 5 days a week as the official working week is the most common but not everywhere and it is a moving target.
You have the number of working days in the previous weeks ( = weeks * 5 ) and then work out the number of working days so far in the current week.
Public holidays are even more localised and would be close to impossible to keep track of.
Fortunately, I am retired so every day is a holiday...
Re: Week number in a Year
Posted: Sun Aug 10, 2025 11:53 am
by BarryG
TassyJim wrote: Sat Jul 06, 2024 10:46 pmThis will cause much eye rolling and complaints from some countries who want every week to start on Sunday (or Monday) including for week number of the year.
As long as it matches the week number shown in the CalendarGadget(), then no eye-rolling or complaints should arise.
I needed a week number algo today, and your code matches the CalendarGadget(). So, thank you, TassyJim!

Re: Week number in a Year
Posted: Sun Aug 10, 2025 6:20 pm
by the.weavster
Don't forget SQLite date functions are available to you:
Code: Select all
SELECT strftime('%V', '2025-08-10') AS weekno
Re: Week number in a Year
Posted: Mon Aug 11, 2025 12:52 am
by Kiffi
the.weavster wrote: Sun Aug 10, 2025 6:20 pm
Don't forget SQLite date functions are available to you:
Code: Select all
SELECT strftime('%V', '2025-08-10') AS weekno

Re: Week number in a Year
Posted: Mon Aug 11, 2025 1:21 am
by BarryG
SQLite? PureBasic doesn't support that? I see no lib for it.
Re: Week number in a Year
Posted: Mon Aug 11, 2025 6:16 am
by jacdelad
BarryG wrote: Mon Aug 11, 2025 1:21 am
SQLite? PureBasic doesn't support that? I see no lib for it.
https://purebasic.developpez.com/docume ... abase.html
Re: Week number in a Year
Posted: Mon Aug 11, 2025 8:36 am
by BarryG
Oh, right.

Under the "Database" section. I was looking for "SQLite" in the index.
