Every line of 'get first day of month python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
721 def first_day_of_month(date): 722 ddays = int(date.strftime("%d")) - 1 723 delta = timedelta(days=ddays) 724 return date - delta
6 def dayOfMonth(M): 7 return (28 if (M == 2) else 31-(M-1)%7%2)
107 def getDaysInMonth(self, mth, year): 108 days = 0 109 if mth in [1, 3, 5, 7, 8, 10, 12]: 110 days = 31 111 elif mth in [4, 6, 9, 11]: 112 days = 30 113 elif (mth == 2 and self.isLeapYear(year)): 114 days = 29 115 else: 116 days = 28 117 return days
517 def daysbetween(day1, month1, year1, day2, month2, year2): 518 """Given two dates it returns the number of days between them. 519 If date1 is earlier than date2 then the result will be positive.""" 520 return daycount(year2, month2, day2) - daycount(year1, month1, day1)
28 def get_mothers_day(self, year): 29 return ( 30 Lithuania.get_nth_weekday_in_month(year, 5, SUN, 1), 31 "Mother's day" 32 )
149 def daysInMonth(self, month): 150 """returns last day of the month as integer 28-31""" 151 if self.isLeapYear(): 152 return _daysInMonthLeapYear[month - 1] 153 else: 154 return _daysInMonthNormal[month - 1]
102 def first_day_of_week(): 103 """Determine the first day of the week for the system locale. 104 105 If the first day of the week cannot be determined then Sunday is assumed. 106 107 Returns (int): a day of the week; 0: Sunday, 1: Monday, 6: Saturday. 108 """ 109 # Python's locale does not have a first day of week so make a system call 110 # http://blogs.gnome.org/patrys/2008/09/29/how-to-determine-the-first-day-of-week/ 111 CMD=("locale", "first_weekday", "week-1stday") 112 process = Popen(CMD, stdout=PIPE, stderr=PIPE) 113 stdout, stderr = process.communicate() 114 if process.returncode != 0: 115 return 0 116 results = stdout.split("\n") 117 if len(results) < 2: 118 return 0 119 day_delta = datetime.timedelta(days=int(results[0]) - 1) 120 base_date = datetime.datetime.strptime(results[1], "%Y%m%d") 121 first_day = base_date + day_delta 122 return int(first_day.strftime("%w"))
270 @property 271 def days_in_month(self): 272 return self.date.days_in_month
10 def get_prev_month_date(): 11 today = date.today() 12 if today.day == 1: 13 if today.month == 1: 14 date_month = date(today.year - 1, 12, 1) 15 else: 16 date_month = date(today.year, today.month - 1, 1) 17 else: 18 date_month = date(today.year, today.month, 1) 19 return date_month
83 def get_month_start(from_day=None): 84 if not from_day: 85 from_day = datetime.date.today() 86 from_day = add_timezone(from_day) 87 return from_day.replace(day=1)