10 examples of 'python get date' in Python

Every line of 'python get date' 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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
254def _getdate(future=0, weekdayname=_weekdayname, monthname=_monthname):
255 from time import gmtime, time
256 now = time()
257 year, month, day, hh, mm, ss, wd, y, z = gmtime(now + future)
258 return '%s, %02d %3s %4d %02d:%02d:%02d GMT' % (weekdayname[wd],
259 day,
260 monthname[month],
261 year,
262 hh,
263 mm,
264 ss)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

15def test_http_date_python(self):
16 format_date_time(time())
15def getdate(d):
16 return asm.getdate_guess(d)
19def parse_date(date):
20 if not date:
21 return None
22 try:
23 return datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
24 except ValueError:
25 d = datetime.datetime.strptime(date, '%Y-%m-%d').date()
26 return d
26def parse_date(date):
27 try:
28 return datetime.strptime(date, "%Y-%m-%d").date()
29 except ValueError:
30 return None
254def date_str(s):
255 return datetime.datetime.strptime(s, '%Y-%m-%d').date()
37def parse_date(date):
38 # Sample: 3-Dec-05
39 # This custom parsing works faster than:
40 # datetime.datetime.strptime(date, "%d-%b-%y")
41 month_abbr = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4,
42 'May': 5, 'Jun': 6, 'Jul': 7, 'Aug': 8,
43 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12}
44
45 date = date.split("-")
46 year = int(date[2]) + 2000
47
48 if year > datetime.datetime.today().year:
49 # it's probably 20th century
50 year -= 100
51
52 month = int(month_abbr[date[1]])
53
54 day = int(date[0])
55 ret = datetime.datetime(year, month, day)
56
57 return ret
43def get_date (self):
44 cd = time.strftime ("%Y%m%d", time.localtime (time.time ()))
45 self.lock.acquire ()
46 if cd not in self.attain_status:
47 self.attain_status [cd] = 0
48 self.lock.release ()
49 return cd
21def date(value, format='%Y-%m-%d'):
22 '''
23 >>> date('2000-01-01')
24 datetime.date(2000, 1, 1)
25 '''
26 return DateTime.strptime(value, format).date()
37def parse_date(date):
38 # Sample: 2005-12-30
39 # This custom parsing works faster than:
40 # datetime.datetime.strptime(date, "%Y-%m-%d")
41 year = int(date[0:4])
42 month = int(date[5:7])
43
44 day = int(date[8:10])
45 ret = datetime.datetime(year, month, day)
46
47 return ret

Related snippets