How to get week-number of year

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
onidarbe
Posts: 84
Joined: Thu Nov 29, 2007 8:03 pm
Location: Belgium, Mechelen

How to get week-number of year

Post by onidarbe »

Dos anyone know how to get the number of the week in a year? So Week 1 to Week 53...
Also getting the first day (monday) of a week-number ?

Thanks
OOo 3.1.X on Ms Windows XP
TerryE
Volunteer
Posts: 1402
Joined: Sat Oct 06, 2007 10:13 pm
Location: UK

Re: How to get week-number of year

Post by TerryE »

The answer to this is different depending on whether you are wanting to use Calc functions or native Basic RTL functions. These are documented online in the OOo Help. Go to the Contents tab and drill down to Macros and Programming->Command Reference->Run-Time Functions, Statements and Operators->Date and Time Functions.

So Year(Date) returns the current year, Weekday(DateSerial(Year(Now),1,1) the day of Jan 1 in the current year, etc. There are a number of definitions of Week Numbering but with these functions it is simple to write a function to implement the one that you want.
Ubuntu 11.04-x64 + LibreOffice 3 and MS free except the boss's Notebook which runs XP + OOo 3.3.
Post Reply