A brief discussion on the issue of dates containing zero values ​​in MySQL database

A brief discussion on the issue of dates containing zero values ​​in MySQL database

By default, MySQL can accept the insertion of 0 values ​​in the date, but in reality, the 0 value in the date has no meaning. This can be achieved by adjusting the MySQL sql_mode variable.

set @@global.sql_mode='STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION';
set @@session.sql_mode='STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION';

example:

There is a table for logging

create table app_logs(
id int not null auto_increment primary key,
log_tm timestamp not null,
log_info varchar(64) not null)
engine=innodb,charset=utf8;

Insert interesting date values ​​into the log table

insert into app_logs(log_tm,log_info) values(now(),'log_info_1');
insert into app_logs(log_tm,log_info) values('2016-12-01','log_info_2');

Insert date values ​​including 0 into the log table

insert into app_logs(log_tm,log_info) values('2016-12-00','log_info_2');
ERROR 1292 (22007): Incorrect datetime value: '2016-12-00' for column 'log_tm' at row 1

The above article briefly discusses the problem of zero values ​​in dates in MySQL database. This is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Mysql optimization techniques for querying dates based on time
  • mysql gets yesterday's date, today's date, tomorrow's date, and the time of the previous hour and the next hour
  • Analyze the selection problem of storing time and date types in MySQL
  • Using Java8's LocalDate and LocalDateTime in JDBC to operate mysql and postgresql
  • MySQL gets the current date and time function
  • How to query records between two dates in MySQL
  • Detailed explanation of MySQL date string timestamp conversion
  • Detailed explanation of mysql to get the current date and format
  • Detailed explanation of date formatting in MySQL
  • How to query the maximum number of consecutive login days between two dates in MySQL
  • How to convert mysql date type and int type
  • mysql records are output in reverse order according to the date field
  • Detailed explanation of commonly used date and time/numeric functions in MySQL (must read)
  • MySql specific functions for judging Chinese characters, dates, and numbers
  • Functions and methods for converting dates and timestamps in MySQL
  • How to get the date a few days before the current date in Mysql
  • Detailed explanation of mysql get current date function and time formatting parameters
  • MySQL date functions and date conversion and formatting functions

<<:  Native js to implement form validation function

>>:  nginx configuration location summary location regular writing and rewrite rule writing

Recommend

How to use CocosCreator to create a shooting game

Analyze the production steps: 1. Prepare resource...

VMware installation of Centos8 system tutorial diagram (command line mode)

Table of contents 1. Software and system image 2....

JS implements multiple tab switching carousel

Carousel animation can improve the appearance and...

In-depth analysis of the slow query problem of MySQL Sending data

Through an example, I shared with you the solutio...

Overview of MySQL Statistics

MySQL executes SQL through the process of SQL par...

Query the data of the day before the current time interval in MySQL

1. Background In actual projects, we will encount...

About the usage and precautions of promise in javascript (recommended)

1. Promise description Promise is a standard buil...

web.config (IIS) and .htaccess (Apache) configuration

xml <?xml version="1.0" encoding=&qu...

MySQL database JDBC programming (Java connects to MySQL)

Table of contents 1. Basic conditions for databas...

Vue implements online preview of PDF files (using pdf.js/iframe/embed)

Preface I am currently working on a high-quality ...

Detailed explanation of using JavaScript WeakMap

A WeakMap object is a collection of key/value pai...

Implementation of Docker private library

Installing and deploying a private Docker Registr...

Methods for optimizing Oracle database with large memory pages in Linux

Preface PC Server has developed to this day and h...