class date(obj=None, *args, start_date=None, readformat=None, to='date', as_date=None, outformat=None, **kwargs)[source]#

Convert any reasonable object – a string, integer, or datetime object, or list/array of any of those – to a date object (or string, pandas, or numpy date). 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; if None, return current date

  • 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() (NB: can also use “format” instead of “readformat”)

  • to (str) – the output format: ‘date’ (default), ‘str’ (or ‘string’), ‘pandas’, or ‘numpy’

  • as_date (bool) – alternate method of choosing between output format of ‘date’ (True) or ‘str’ (False); if None, use “to” instead

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

  • kwargs (dict) – only used for deprecated argument aliases


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', to='str') # 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
New in version 3.0.0: added “to” argument, and support for pd.Timestamp and np.datetime64 output; allow None