# daystart - script and chart function

This function returns a value corresponding to a timestamp with the first millisecond of the day contained in the time argument. The default output format will be the TimestampFormat set in the script.

Syntax:

DayStart(time[, [period\_no[, day\_start]])

**Return data type:** dual

Arguments:

DayStart arguments

| Argument | Description |
| --- | --- |
| time | The timestamp to evaluate. |
| period\_no | period\_no is an<br>integer, or expression that resolves to an integer, where the value 0 indicates the day that contains time.<br>Negative values in period\_no indicate<br>preceding days and positive values indicate succeeding days. |
| day\_start | To specify days not starting at midnight, indicate an offset as a<br>fraction of a day in day\_start. For example, 0.125 to denote 3 AM. |

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:

`daystart('25/01/2013 16:45:00')`

Returns 25/01/2013 00:00:00.

Example 2:

`daystart('25/01/2013 16:45:00', -1)`

Returns 24/01/2013 00:00:00.

Example 3:

`daystart('25/01/2013 16:45:00', 0, 0.5
 )`

Returns 25/01/2013 12:00:00.

Example 4:

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 finds the timestamp that marks the beginning of the day after each invoice date in the table.

`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 *,` `DayStart(InvDate, 1) AS DStart` `Resident TempTable;`

`Drop table TempTable;`

The resulting table contains the original dates and a column with the return value of the daystart() function. You can display the full timestamp by specifying the formatting in the chart properties.

Example 4 results

| InvDate | DStart |
| --- | --- |
| 28/03/2012 | 29/03/2012 00:00:00 |
| 10/12/2012 | 11/12/2012 00:00:00 |
| 5/2/2013 | 06/02/2013 00:00:00 |
| 31/3/2013 | 01/04/2013 00:00:00 |
| 19/5/2013 | 20/05/2013 00:00:00 |
| 15/9/2013 | 16/09/2013 00:00:00 |
| 11/12/2013 | 12/12/2013 00:00:00 |
| 2/3/2014 | 03/03/2014 00:00:00 |
| 14/5/2014 | 15/05/2014 00:00:00 |
| 13/6/2014 | 14/06/2014 00:00:00 |
| 7/7/2014 | 08/07/2014 00:00:00 |
| 4/8/2014 | 05/08/2014 00:00:00 |