Python | numpy.datetime64 () method

With the numpy.datetime64() method we can get the date in a numpy array in a specific format, i.e. year-month-day using numpy. datetime64 () .

Syntax: numpy.datetime64 (date)
Return: Return the date in a format `yyyy-mm-dd`.

Example # 1:
In this example, we see that with numpy.datetime64 () we can get the date in a specific format i.e. yyyy-mm-dd.

# NumPy import

import numpy as np

 
# using numpy.datetime64 () method

gfg = np.array (np.datetime64 ( `2019-08-26` ))

 

print (gfg)

Output:

array (`2019-08-26 ′, dtype =` datetime64 [D] `)

Example # 2:

# impo pt NumPy

import numpy as np

 
# using the numpy.datetime64 () method

gfg = np.array (np.datetime64 ( `2019-08 ` , ` D` ))

 

print (gfg)

Output:

array (`2019-08-01 ′, dtype =` datetime64 [D] `)