Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

queries while retrieving data from list in python

Tags:

python

I have a list in python which has below data . each data represent a table name

[tablename_20211011, tablename_20201010, tablename_20211009, tablename_20211009, tablename_20211008]

20211011 -- this is the date when table got created how i can fetch the table names which are created in last 1 year python.

if crteria is 1 yr then result should be tablename_20211011,tablename_20211009, tablename_20211008,tablename_20211009

like image 427
Yatindra Kumar Janghel Avatar asked Jun 06 '26 08:06

Yatindra Kumar Janghel


1 Answers

!!!works!!! here you dont need to mention last year date manually it does the job automatically

from datetime import date
(datetime.datetime.now() - datetime.timedelta(days=365)).strftime("%Y%m%d")
d1 = today.strftime("%Y%m%d")
#this gives you date of last year

[x for x in a if x[:-8]>=d1]

this returns the items after the given date

like image 127
gilf0yle Avatar answered Jun 07 '26 23:06

gilf0yle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!