What do you want to save?
Add Code snippet
New code examples
-
SQL 2022-01-29 12:00:14
mysql connector/python query example
Press CTRL+C to copy import datetime import mysql.connector cnx = mysql.connector.connect(user='scott', database='employees') cursor = cnx.cursor() query = ("SELECT first_name, last_name, hire_date FROM employees " "WHERE hire_da... Add solution -
Python 2022-01-27 22:05:02
add 3 years to a given date in python code
import datetime from datetime import date def addYears(d, years): try: #Return same day of the current year return d.replace(year = d.year + years) except ValueError: #If not same day, it will return other, i.e. February 29 to Mar... Add solution -
Other 2021-11-01 22:27:07
string to datetimefield in django
>>> user = User.objects.get(id=1) >>> date_str = "2018-03-11" >>> from django.utils.dateparse import parse_date // Way 1 >>> temp_date = parse_date(date_str) >>> a1 = Article(headline="String con... Add solution -
Python 2021-10-19 06:17:04
f string repr
# If you want to use repr in f-string use "!r" # Normal behavior (using str) >>> color = "blue\ngreen" >>> day = datetime.date(2020, 6, 4) >>> f"Color is {color} and day is {day}" 'Color is blue\ngr... Add solution -
Python 2021-09-28 23:13:04
python add one month to a date
import datetime import calendar def add_months(sourcedate, months): month = sourcedate.month - 1 + months year = sourcedate.year + month // 12 month = month % 12 + 1 day = min(sourcedate.day, calendar.monthrange(year,month)[1]) return... Add solution