Python parsedatetime: get current month / first of the month -
i'm using parsedatetime library in python script , appears "last month" works , "next month" not "this month."
what missing? there way first day of current month?
edit: sorry, here's code:
import parsedatetime.parsedatetime pdt p = pdt.calendar() res = p.parse('this month') print(str(res)) returns:
(time.struct_time(tm_year=2015, tm_mon=7, tm_mday=13, tm_hour=16, tm_min=22, tm_sec=10, tm_wday=0, tm_yday=194, tm_isdst=0), 0)
i've never used parsedatetime though that's interesting way first of month. still, this:
>>> datetime.datetime.now().replace(day=1, hour=0, minute=0, second=0) it's less wasteful of resources, too, since don't have parse text @ runtime, that's aside, really.
you can convert time.struct_time via timetuple():
>>> datetime.datetime.now().replace(day=1, hour=0, minute=0, second=0).timetuple() time.struct_time(tm_year=2015, tm_mon=7, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=182, tm_isdst=-1)
Comments
Post a Comment