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

jQuery realizes the shuttle box function

This article example shares the specific code of ...

CSS text alignment implementation code

When making forms, we often encounter the situati...

CSS3 custom scroll bar style::webkit-scrollbar sample code detailed explanation

The default scroll bar style in Windows is ugly, ...

Typescript+react to achieve simple drag and drop effects on mobile and PC

This article shares the specific code of typescri...

Vue based on Element button permission implementation solution

Background requirements: The ERP system needs to ...

Windows platform configuration 5.7 version + MySQL database service

Includes the process of initializing the root use...

Solution to define the minimum height of span has no effect

The span tag is often used when making HTML web pa...

Detailed steps to install Docker 1.8 on CentOS 7

Docker supports running on the following CentOS v...

How to solve the problem of too many open files in Linux

The cause is that the process opens a number of f...

How to install openssh from source code in centos 7

Environment: CentOS 7.1.1503 Minimum Installation...

Detailed usage of Vue more filter widget

This article example shares the implementation me...

React implements the sample code of Radio component

This article aims to use the clearest structure t...