O'Reilly logo

NumPy Cookbook - Second Edition by Ivan Idris

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the datetime64 type and related API

The datetime64 type represents a date and the corresponding time. You need NumPy 1.7.0 or later versions to use this data type.

How to do it...

To get acquainted with datetime64, follow these steps:

  1. Create a datetime64 from a string, as follows:
    print(np.datetime64('2015-05-21'))

    The preceding line prints the following output:

    numpy.datetime64('2015-05-21')

    We created a datetime64 type for May 21, 2015, using the YYYY-MM-DD format, where Y corresponds to the year, M corresponds to the month, and D corresponds to the day of the month. NumPy complies with the ISO 8601 standard—an international standard for representing dates and times.

  2. ISO 8601 also defines the YYYY-MM-DD, YYYY-MM, and YYYYMMDD formats. Check these ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required