Skip to main content

yeartodate - script and chart function

This function finds if the input date falls within the year of the date the script was last loaded, and returns True if it does, False if it does not.


YearToDate(timestamp [ , yearoffset [ , firstmonth [ , todaydate] ] ])


Return data type: Boolean

If none of the optional parameters are used, the year to date means any date within one calendar year from January 1 up to and including the date of the last script execution.


Argument Description
timestamp The date to evaluate as a timestamp or expression resolving to a timestamp, to convert, for example '2012-10-12'.

By specifying a yearoffset, yeartodate returns True for the same period in another year. A negative yearoffset indicates a previous year, a positive offset a future year. The most recent year-to-date is achieved by specifying yearoffset = -1. If omitted, 0 is assumed.


By specifying a firstmonth between 1 and 12 (1 if omitted) the beginning of the year may be moved forward to the first day of any month. For example, if you want to work with a fiscal year beginning on May 1, specify firstmonth = 5.

todaydate By specifying a todaydate (timestamp of the last script execution if omitted) it is possible to move the day used as the upper boundary of the period.