How to insert a date into MySQL using Python

0 votes

Hi Guys,

I have installed MySql connector so that I can connect MySql server from my Python code. Can anyone tell me how do I insert a date into MySQL using Python?

Jul 15, 2020 in Python by akhtar
• 38,260 points
8,266 views

1 answer to this question.

0 votes

Hi@akhtar,
You can use the DateTime module to insert a date into MySql. Use the below-given code in your program.

import datetime 
a = datetime.datetime.strptime('my date', "%b %d %Y %H:%M") 
cursor.execute('INSERT INTO myTable (Date) VALUES(%s)', (a.strftime('%Y-%m-%d %H:%M:%S'),))
    answered Jul 15, 2020 by MD
    • 95,460 points

    Related Questions In Python

    0 votes
    1 answer

    How to import an image into a csv file using python?

    I am sure you are aware CSV ...READ MORE

    answered Jun 25, 2020 in Python by Bhanu Kumar
    7,955 views
    0 votes
    1 answer

    How to merge multiple json objects into a single json object using python

    You may do like this but it ...READ MORE

    answered Nov 22, 2020 in Python by Gitika
    • 65,770 points
    19,375 views
    +2 votes
    2 answers

    How to make a laplacian pyramid using OpenCV python?

    down voteacceptTheeThe problem is that you're iterating ...READ MORE

    answered Apr 3, 2018 in Python by charlie_brown
    • 7,720 points
    4,943 views
    0 votes
    2 answers

    How do I connect to a MySQL Database in Python?

    connect mysql database with python import MySQLdb db = ...READ MORE

    answered Mar 28, 2019 in Python by rajesh
    • 1,270 points
    1,910 views
    0 votes
    1 answer

    Error:Python3.4 can't install mysql-python

    Hello @kartik, You can resolved this by the ...READ MORE

    answered Jun 24, 2020 in Python by Niroj
    • 82,840 points
    2,171 views
    0 votes
    1 answer

    How to create MySql database using Python?

    Hi@akhtar, You need to use MySQL connector in ...READ MORE

    answered Jul 15, 2020 in Python by MD
    • 95,460 points
    855 views
    0 votes
    1 answer

    mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported

    Hi@akhtar, According to SQL documentation for python library. you ...READ MORE

    answered Jul 15, 2020 in Python by MD
    • 95,460 points
    31,419 views
    0 votes
    1 answer

    ProgrammingError: not all arguments converted during string formatting

    Sorted!!!! just found the solution, 1 - apparently ...READ MORE

    answered Sep 10, 2018 in Python by Priyaj
    • 58,020 points
    20,320 views
    0 votes
    1 answer

    How to transfer multiple lines in a file using python?

    Hi@akhtar, I don't know it will help you ...READ MORE

    answered Mar 31, 2020 in Python by MD
    • 95,460 points
    1,172 views
    0 votes
    1 answer

    How to crop face from a photo using cv2 in python?

    Hi@akhtar, You can do this task using cv2 ...READ MORE

    answered Apr 9, 2020 in Python by MD
    • 95,460 points
    909 views
    webinar REGISTER FOR FREE WEBINAR X
    REGISTER NOW
    webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP