Friday, September 5, 2025
HomeLanguagesPython | numpy.datetime64() method

Python | numpy.datetime64() method

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

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

Example #1 :
In this example we can see that by using numpy.datetime64() method, we are able to get the date in the particular format i.e yyyy-mm-dd.




# import numpy
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 :




# import numpy
import numpy as np
  
# using numpy.datetime64() method
gfg = np.array(np.datetime64('2019-08', 'D'))
  
print(gfg)


Output :

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

RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11860 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS