1
from datetime import datetime

today=datetime.today().strftime('%Y,%m,%d')

start=dt.date(2017,9,22)
end = dt.date(today)

I want to get today timestamp in python, I tried this with error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-57-e64689f2e644> in <module>
      4 
      5 start=dt.date(2017,9,22)
----> 6 end = dt.date(today)
      7 
      8 s=dt.date(2020,9,16)

TypeError: an integer is required (got type str)
Ruli
  • 2,592
  • 12
  • 30
  • 40
kenneth c
  • 21
  • 1
  • 5
  • you have not defined 'dt' in line 3 of your code . Also since you have imported datetime from datetime your line 4 doesnt work . just use import datetime and this below line should work start = datetime.date(2017,9,22) – Bharath Oct 01 '20 at 15:11
  • Please mark this question as answered. Enough people have given the right solutions, its only right thing to do - to mark an answer accepted. If not please mention what you were expecting and how the solution was not right. Thanks. – Bharath Oct 04 '20 at 04:25

2 Answers2

4

To get the date for today you can use datetime.date.today().

import datetime

start = datetime.date(2017, 9, 22)
end = datetime.date.today()
monkut
  • 42,176
  • 24
  • 124
  • 155
1

you have not defined 'dt' in line 3 of your code . Also since you have imported datetime from datetime your line 4 doesnt work . just use import datetime and this below line should work start = datetime.date(2017,9,22)

I would sugges same answer as suggested by @monkut change your code to below

import datetime
datetime.datetime.today().strftime('%Y,%m,%d')
start=datetime.date(2017,9,22)
end = today
Bharath
  • 406
  • 2
  • 13