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

Three Discussions on Iframe Adaptive Height Code

When building a B/S system interface, you often en...

IE6/7 is going to be a mess: empty text node height issue

Preface: Use debugbar to view document code in iet...

WeChat applet implements sorting function based on date and time

I recently took over a small program project, and...

Oracle VM VirtualBox installation of CentOS7 operating system tutorial diagram

Table of contents Installation Steps Environment ...

8 essential JavaScript code snippets for your project

Table of contents 1. Get the file extension 2. Co...

How to replace all tags in html text

(?i) means do not match case. Replace all uppercas...

Design a data collector with vue

Table of contents Scenario Core Issues Status mon...

JavaScript implements mouse control of free moving window

This article shares the specific code of JavaScri...

MySQL 5.7.17 installation and configuration tutorial under Linux (Ubuntu)

Preface I have installed MySQL 5.6 before. Three ...

Introduction and use of five controllers in K8S

Table of contents Controller type of k8s Relation...

...

How to set up a deployment project under Linux system

1. Modify the firewall settings and open the corr...

Docker dynamically exposes ports to containers

View the IP address of the Container docker inspe...

Summary of SQL deduplication methods

When using SQL to extract data, we often encounte...