# inlunarweek - script and chart function

This function returns true if timestamp lies inside the lunar week containing base\_date. Lunar weeks in QlikView are defined by counting 1 January as the first day of the week.

Syntax:

InLunarWeek (timestamp, base\_date, period\_no[, first\_week\_day])

**Return data type:** Boolean

Arguments:

InLunarWeek arguments

| Argument | Description |
| --- | --- |
| timestamp | The date that you want to compare with base\_date. |
| base\_date | Date that is used to evaluate the lunar week. |
| period\_no | The lunar<br>week can be offset by period\_no.<br>period\_no is an integer, where the<br>value 0 indicates the lunar week which contains base\_date.<br>Negative values in period\_no indicate<br>preceding lunar weeks and positive values indicate succeeding lunar weeks. |
| first\_week\_day | An offset that may be greater than or less than zero. This changes the beginning of the year by the specified number of days and/or fractions of<br>a day. |

Example 1:

`inlunarweek('12/01/2013', '14/01/2013', 
 0)`

Returns True. Because the value of timestamp, 12/01/2013 falls in the week 08/01/2013 to 14/01/2013.

Example 2:

`inlunarweek('12/01/2013', '07/01/2013', 
 0)`

Returns False. Because the base\_date 07/01/2013 is in the lunar week defined as 01/01/2013 to 07/01/2013.

Example 3:

`inlunarweek('12/01/2013', '14/01/2013', 
 -1)`

Returns False. Because specifying a value of period\_no as -1 shifts the week to the previous week, 01/01/2013 to 07/01/2013.

Example 4:

`inlunarweek('07/01/2013', '14/01/2013', 
 -1)`

Returns True. In comparison with the previous example, the timestamp is in the week after taking into account the shift backwards.

Example 5:

`inlunarweek('11/01/2006', '08/01/2006', 
 0, 3)`

Returns False. Because specifying a value for first\_week\_day as 3 means the start of the year is calculated from 04/01/2013, and so the value of base\_date falls in the first week, and the value of timestamp falls in the week 11/01/2013 to 17/01/2013.

Example 6:

Add the example script to your document and run it. Then add, at least, the fields listed in the results column to a sheet in your document to see the result.

This example checks if an invoice date falls in the week shifted from the value of base\_date by four weeks.

`TempTable:` `LOAD RecNo() as InvID, * Inline [` `InvDate` `28/03/2012` `10/12/2012` `5/2/2013` `31/3/2013` `19/5/2013` `15/9/2013` `11/12/2013` `2/3/2014` `14/5/2014` `13/6/2014` `7/7/2014` `4/8/2014` `];` ` ` `InvoiceData:` `LOAD *,` `InLunarWeek(InvDate, '11/01/2013', 4) AS InLWeekPlus4` `Resident TempTable;`

`Drop table TempTable;`

The resulting table contains the original dates and a column with the return value of the inlunarweek() function.

The function returns True for the value of InvDate5/2/2013 because the value of base\_date, 11/01/2013, is shifted by four weeks, and so falls in the week 5/02/2013 to 11/02/2013.

Example 6 results

| InvDate | InLWeekPlus4 |
| --- | --- |
| 28/03/2012 | 0 (False) |
| 10/12/2012 | 0 (False) |
| 5/2/2013 | -1 (True) |
| 31/3/2013 | 0 (False) |
| 19/5/2013 | 0 (False) |
| 15/9/2013 | 0 (False) |
| 11/12/2013 | 0 (False) |
| 2/3/2014 | 0 (False) |
| 14/5/2014 | 0 (False) |
| 13/6/2014 | 0 (False) |
| 7/7/2014 | 0 (False) |
| 4/8/2014 | 0 (False) |