Week number in a Year

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
miskox
Enthusiast
Enthusiast
Posts: 107
Joined: Sun Aug 27, 2017 7:37 pm
Location: Slovenia

Week number in a Year

Post 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
AZJIO
Addict
Addict
Posts: 2143
Joined: Sun May 14, 2017 1:48 am

Re: Week number in a Year

Post 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)
User avatar
jacdelad
Addict
Addict
Posts: 1992
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Week number in a Year

Post 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.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
TassyJim
Enthusiast
Enthusiast
Posts: 183
Joined: Sun Jun 16, 2013 6:27 am
Location: Tasmania (Australia)

Re: Week number in a Year

Post 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...
Post Reply