sciris.sc_datetime.datetoyear

datetoyear(dateobj, dateformat=None)[source]

Convert a DateTime instance to decimal year.

Parameters
  • dateobj (date, str) – The datetime instance to convert

  • dateformat (str) – If dateobj is a string, the optional date conversion format to use

Returns

Equivalent decimal year

Example:

sc.datetoyear('2010-07-01') # Returns approximately 2010.5

By Luke Davis from https://stackoverflow.com/a/42424261, adapted by Romesh Abeysuriya.

New in version 1.0.0.