<commit_before>.. currentmodule:: numpy

.. _arrays.datetime:

************************
Datetimes and Timedeltas
************************

.. versionadded:: 1.7.0

Starting in NumPy 1.7, there are core array data types which natively
support datetime functionality. The data type is called "datetime64",
so named because "datetime" is already taken by the datetime library
included in Python.

.. note:: The datetime API is *experimental* in 1.7.0, and may undergo changes
   in future versions of NumPy.

Basic Datetimes
===============

The most basic way to create datetimes is from strings in
ISO 8601 date, datetime format or from integer to UNIX time. 
The unit for internal storage is automatically selected from the 
form of the string, and can be either a :ref:`date unit <arrays.dtypes.dateunits>` or a
:ref:`time unit <arrays.dtypes.timeunits>`. The date units are years ('Y'),
months ('M'), weeks ('W'), and days ('D'), while the time units are
hours ('h'), minutes ('m'), seconds ('s'), milliseconds ('ms'), and
some additional SI-prefix seconds-based units. The datetime64 data type 
also accepts the string "NAT", in any combination of lowercase/uppercase
letters, for a "Not A Time" value.

.. admonition:: Example

    A simple ISO date:

    >>> np.datetime64('2005-02-25')
    numpy.datetime64('2005-02-25')
    
    UNIX time, by providing integer and a date unit :

    >>> np.datetime64(1, 'Y')
    numpy.datetime64('1971')   

    Using months for the unit:

    >>> np.datetime64('2005-02')
    numpy.datetime64('2005-02')

    Specifying just the month, but forcing a 'days' unit:<commit_msg>DOC: resolves #14299 - deleting the note<commit_after>.. currentmodule:: numpy

.. _arrays.datetime:

************************
Datetimes and Timedeltas
************************

.. versionadded:: 1.7.0

Starting in NumPy 1.7, there are core array data types which natively
support datetime functionality. The data type is called "datetime64",
so named because "datetime" is already taken by the datetime library
included in Python.


Basic Datetimes
===============

The most basic way to create datetimes is from strings in
ISO 8601 date, datetime format or from integer to UNIX time. 
The unit for internal storage is automatically selected from the 
form of the string, and can be either a :ref:`date unit <arrays.dtypes.dateunits>` or a
:ref:`time unit <arrays.dtypes.timeunits>`. The date units are years ('Y'),
months ('M'), weeks ('W'), and days ('D'), while the time units are
hours ('h'), minutes ('m'), seconds ('s'), milliseconds ('ms'), and
some additional SI-prefix seconds-based units. The datetime64 data type 
also accepts the string "NAT", in any combination of lowercase/uppercase
letters, for a "Not A Time" value.

.. admonition:: Example

    A simple ISO date:

    >>> np.datetime64('2005-02-25')
    numpy.datetime64('2005-02-25')
    
    UNIX time, by providing integer and a date unit:

    >>> np.datetime64(1, 'Y')
    numpy.datetime64('1971')   

    Using months for the unit:

    >>> np.datetime64('2005-02')
    numpy.datetime64('2005-02')

    Specifying just the month, but forcing a 'days' unit:
{'fraction_non_alphanumeric': 0.14258494760241347, 'fraction_numerical': 0.039377580184185454, 'mean_word_length': 4.056179775280899, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7575970', 'n_tokens_mistral': 984, 'n_tokens_neox': 864, 'n_words': 389}