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

  • Home
  • SEARCH
  • 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 735093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:26:56+00:00 2026-05-14T07:26:56+00:00

When I try to put a value into a DATE field which is invalid,

  • 0

When I try to put a value into a DATE field which is invalid, MySQL seems to use 0000-00-00 instead. Is there a way I can do this “check” without updating a DATE field? And to do it from for example PHP?

Like, is there a way I can query the MySQL server and ask “Hey, is this DATE, TIME or DATETIME valid to you?”

Or is there maybe an even better way of doing it?

  • 1 1 Answer
  • 0 Views
  • 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. Editorial Team
    Editorial Team
    2026-05-14T07:26:57+00:00Added an answer on May 14, 2026 at 7:26 am

    If you choose a server mode for the MySQL server that doesn’t allow invalid date values a query containing such a malformed date representation will cause an error instead of (silently) assuming 0000-00-00
    see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html

    e.g.

    $pdo = new PDO('mysql:host=localhost;dbname=test', 'localonly', 'localonly'); 
    $pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    
    $pdo->exec('CREATE TEMPORARY TABLE foo (id int auto_increment, d datetime, primary key(id))');
    
    $query = "INSERT INTO foo (d) VALUES ('2010-02-31 12:15:18')";
    foreach( array('ALLOW_INVALID_DATES', 'STRICT_ALL_TABLES') as $mode ) {
      echo $mode, ": "; flush();
      $pdo->exec("SET SESSION sql_mode='$mode'");
      $pdo->exec($query);
      echo "Ok.\n";
    }
    

    prints

    ALLOW_INVALID_DATES: Ok.
    STRICT_ALL_TABLES: 
    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2010-02-31 12:15:18' for column 'd' at row 1' in [...]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I try to put some condition value into ContentValues variable, there is inserting
I try to put the value of lastPointX into a label text, but doesn't
i try to put the progress bar into the notification. but the problem is
I try to put sixteen checkbuttons into frame, placing them into four columns like:
I’m using C# and WinForms to try and put just the date from a
I am trying to take the entire post array and put each value into
I try to put some HTML link behind input text and I try to
Scenario : I'll try to put an analogy with the loan broker example from
im near to finish my app and when try to put in onlin server
for some reason then i duplicate movie clip and try to put it in

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.