Search code examples
pythonstringdatetimetypeerror

Python TypeError: 'datetime.datetime' object is not subscriptable. Unable to print desired number


Using this codecode I am trying to extract just the day number from this date. In this example it would be 30. When I try to print with the range[] function I get the error. How can I just print this desired number?

I am unable to turn into a str function or use the range function to select my desired number.


Solution

  • If you are trying to extract the day, you should use .day from the datetime module.

    dt_m = datetime.datetime.fromtimestamp(m_time)
    print(dt_m.day)
    

    The output will be the day, or in your case 30.