date(obj, *args, start_date=None, readformat=None, outformat=None, as_date=True, **kwargs)[source]

Convert any reasonable object – a string, integer, or datetime object, or list/array of any of those – to a date object. To convert an integer to a date, you must supply a start date.

Caution: while this function and sc.readdate() are similar, and indeed this function calls sc.readdate() if the input is a string, in this function an integer is treated as a number of days from start_date, while for sc.readdate() it is treated as a timestamp in seconds.

Note: in this and other date functions, arguments work either with or without underscores (e.g. start_date or startdate)

  • obj (str/int/date/datetime/list/array) – the object to convert

  • args (str/int/date/datetime) – additional objects to convert

  • start_date (str/date/datetime) – the starting date, if an integer is supplied

  • readformat (str/list) – the format to read the date in; passed to sc.readdate()

  • outformat (str) – the format to output the date in, if returning a string

  • as_date (bool) – whether to return as a datetime date instead of a string


either a single date object, or a list of them (matching input data type where possible)

Return type

dates (date or list)

Examples:'2020-04-05') # Returns, 4, 5)[35,36,37], start_date='2020-01-01', as_date=False) # Returns ['2020-02-05', '2020-02-06', '2020-02-07'], readformat='posix') # Interpret as a POSIX timestamp
New in version 1.0.0.
New in version 1.2.2: “readformat” argument; renamed “dateformat” to “outformat”
New in version 2.0.0: support for np.datetime64 objects