Skip to content
Related Articles

Related Articles

Display all the dates for a particular month using NumPy
  • Last Updated : 26 Nov, 2020

In NumPy to display all the dates for a particular month, we can do it with the help of NumPy.arrange() pass the first parameter the particular month and the second parameter the next month and the third parameter is the datatype datetime64[D]. It will return all the dates for the particular month.

Syntax: numpy.arange([start, ] stop, [step, ] dtype=None)

Parameters:

start : Start of interval

stop : End of interval



Step : Spacing between values

dtype : The type of the output array. If dtype is not given, infer the data type from the other input arguments.

Returns:

arange : ndarray

Example 1#:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

import numpy as np
  
  
# dates of july  2020
print(np.arange('2012-07', '2020-08',
                dtype='datetime64[D]'))

chevron_right


Output:

[‘2012-07-01’ ‘2012-07-02’ ‘2012-07-03’ … ‘2020-07-29’ ‘2020-07-30’
‘2020-07-31’]



Example 2#:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

import numpy as np
  
# dates of september  2020
print(np.arange('2012-09', '2020-10',
                dtype='datetime64[D]'))

chevron_right


Output:

[‘2012-09-01’ ‘2012-09-02’ ‘2012-09-03’ … ‘2020-09-28’ ‘2020-09-29’
‘2020-09-30’]

Example 3#:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

import numpy as np
  
# dates of Feb  2020
print(np.arange('2012-02', '2020-03',
                dtype='datetime64[D]'))

chevron_right


Output:

[‘2012-02-01’ ‘2012-02-02’ ‘2012-02-03’ … ‘2020-02-27’ ‘2020-02-28’
‘2020-02-29’]

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :