# inyear - script and chart function

This function returns True if timestamp lies inside the year containing base\_date.

Syntax:

InYear (timestamp, base\_date, period\_no [, first\_month\_of\_year])

**Return data type:** Boolean

Arguments:

InYear arguments

| Argument | Description |
| --- | --- |
| timestamp | The date that you want to compare with base\_date. |
| base\_date | Date that is used to evaluate the year. |
| period\_no | The year can be offset by period\_no.<br>period\_no is an integer, where the<br>value 0 indicates the year that contains base\_date.<br>Negative values in period\_no indicate<br>preceding years, and positive values indicate succeeding years. |
| first\_month\_of\_year | If you<br>want to work with (fiscal) years not starting in January, indicate<br>a value between 2 and 12 in first\_month\_of\_year. |

Examples and results:

These examples use the date format DD/MM/YYYY. The date format is specified in the SET DateFormat statement at the top of your load script. Change the format in the examples to suit your requirements.

Example 1:

`inyear ('25/01/2013', '01/01/2013', 
 0 )`

Returns True

Example 2:

`inyear ('25/01/2012', '01/01/2013', 
 0)`

Returns False

Example 3:

`inyear ('25/01/2013', '01/01/2013', 
 -1)`

Returns False

Example 4:

`inyear ('25/01/2012', '01/01/2013', 
 -1 )`

Returns True

Example 5:

`inyear ('25/01/2013', '01/01/2013', 
 0, 3)`

Returns True

Example 6:

`inyear ('25/03/2013', '01/07/2013', 
 0, 3 )`

Returns False. The values of base\_date and first\_month\_of\_year specify that timestamp must fall within 01/03/2012 and 28/02/2013

Example 7:

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 fiscal year specified by setting the value of first\_month\_of\_year to 4, and having the base\_date between 1/4/2012 and 31/03/2013.

`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` `];` ` `

Test if InvDate is in the financial year 1/04/2012 to 31/03/2013:

`InvoiceData:` `LOAD *,` `InYear(InvDate, '31/01/2013', 0, 4) AS FinYr1213` `Resident TempTable;`

`Drop table TempTable;`

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

Example 7 results

| InvDate | FinYr1213 |
| --- | --- |
| 28/03/2012 | 0 (False) |
| 10/12/2012 | -1 (True) |
| 5/2/2013 | -1 (True) |
| 31/3/2013 | -1 (True) |
| 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) |