Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 105893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:30:39+00:00 2026-05-11T01:30:39+00:00

I have a DateTime which I want to store in a Date MySQL column.

  • 0

I have a DateTime which I want to store in a Date MySQL column. I am using MySQLi and prepared statements.

When binding parameters, I cannot specify date as a type, only strings and integers.

How do I convert the DateTime to a MySQL date string representation? There is very little documentation on the DateTime class.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:30:40+00:00Added an answer on May 11, 2026 at 1:30 am

    I almost closed this as a duplicate of Convert from MySQL datetime to another format with PHP but I think it’s actually the reverse problem. That question asked how to format a date fetched from MySQL, and you’re asking how to format a date for input to a query.

    Option 1:

    SELECT * FROM MyTable WHERE DateTimeCol = ? 

    You can format the value to the YYYY-MM-DD HH:MM format MySQL wants:

    <?php $mysql_date = date('Y-m-d H:i:s', $timestamp); ?> 

    Then submit it as a string parameter to the query.

    Option 2:

    SELECT * FROM MyTable WHERE DateTimeCol = FROM_UNIXTIME(?) 

    Then you can submit the timestamp value as a numeric parameter to the query.

    Option 3:

    SELECT * FROM MyTable WHERE DateTimeCol = STR_TO_DATE(?, '%m/%d/%y') 

    You can submit a wide variety of string representations of date/time, if you specify the formatting to MySQL’s STR_TO_DATE() function. For the formatting codes, see the DATE_FORMAT() function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created mysql to delete table rows, which have lower DATETIME value than
I have added a field in my MySQL Database, which is a DateTime field.
I have a datetime column in db that I want to transform into a
I have premiere_poland column in database table which is date type. /** @Column(type=date, nullable=TRUE)
I have a DATETIME column on my table which stores when a record was
I have a datetime called dispatched_time which I am subtracting from Time.now which results
I have a 'created_date' DATETIME field which I would like to be populated with
I have a Oracle procedure to which I have to pass a datetime value
I have a table users which has a primary key userid and a datetime
So I have a flashobject which I need to pass a formatted DateTime string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.