Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add and Compare Datetime in Python

How do I write this pseudocode in Python? With 'created_date' being a datetime object.

if (created_date + 30days) < now:
  print 'valid'
else:
  print 'expired'
like image 568
johnnytee Avatar asked Dec 12 '22 14:12

johnnytee


1 Answers

import datetime as DT
if (created_date + DT.timedelta(days=30)) < DT.datetime.now():
    print('valid')
else:
    print('expired')
like image 125
unutbu Avatar answered Dec 15 '22 04:12

unutbu