mysql中时间日期 datetime字段保存日期出现0000-00-00
如果大家注意一下datetime日期格式类型的话就应该可以不要问了,datetime日期必须是 2012-01-01 10:10:10 这种,否则就有可能出来0000-00-00
正确的php sql语句写法应该是:
代码如下 | 复制代码 |
$sql = "insert into table(datetime) values('".date("Y-m-d h:i:s",time())."')"; //datetime字段的类型为“datetime”, |
注意后面要插入的数据是字符串要加“单引号”。
这样就没错了,时间日期类型插入数据库之前要格式化,否则就出现插入的全是0000-00-00的问题。
个人建义,大家保存时间时最好使用int类型保存time()生成的日期这样操作会更方便。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The manipulation of date and time values is an important aspect of programming, and the Python language provides a useful built-in module for this called datetime. However, in some cases, you may need to convert a DateTime object to an integer value in order to perform specific operations or calculations. There are multiple ways to convert a DateTime to an integer in Python, each with its own advantages and disadvantages. In this article, we'll take a closer look at these methods and examine when each method is appropriate to use. After reading this article, you will have a complete understanding of how to efficiently convert DateTime objects to integers in Python and be able to choose the most appropriate method for your specific programming task. Method 1: Use timestamp

Getting today's date using DateTime.Today function in C# requires specific code examples C# is an object-oriented programming language that provides many built-in classes and methods to handle dates and times. Among them, the DateTime class has some very useful methods, such as the Today property, which can be used to obtain today's date. Here is a sample code that demonstrates how to get today's date using the DateTime.Today function in C#: usingSystem;

In golang, regular expressions are a very powerful tool that can easily verify strings in various formats. Date format is also one of the common validation needs. This article explains how to use regular expressions to validate common date formats. In golang, we can use the "regexp" package to perform regular expression operations. This package provides functions and types for writing and executing regular expressions. The following are some common date formats and their corresponding regular expressions: YYYY-MM-DD the day

Use the DateTime.AddDays function in C# to add a specified number of days to a date. In C# programming, we often encounter situations where we need to add and subtract dates. The DateTime class in C# provides many convenient methods and properties for working with dates and times, including the AddDays function, which can be used to add a specified number of days to a specified date. Here is a specific code example that demonstrates how to use the DateTime.AddDays function to add a specified number of days to a date:

All data are automatically assigned a "DOB" (Date of Birth) at the beginning. Therefore, it is inevitable to encounter date and time data when processing data at some point. This tutorial will take you through the datetime module in Python and using some peripheral libraries such as pandas and pytz. In Python, anything related to date and time is handled by the datetime module, which further divides the module into 5 different classes. Classes are simply data types that correspond to objects. The following figure summarizes the 5 datetime classes in Python along with commonly used attributes and examples. 3 useful snippets 1. Convert string to datetime format, maybe using datet

There are many excellent calendar libraries and date libraries in Python for us to use. These libraries can help us handle date and calendar related operations. Next, I will introduce you to several common choices and provide corresponding code examples. Datetime library: Datetime is Python's built-in date and time processing module. It provides many date and time related classes and methods, which can be used to process dates, times, time differences and other operations. Sample code: importdatetime#Get the current date

How to solve: Java Date Error: Date format mismatch When using Java for date processing, you often encounter date format mismatch errors. This error is usually caused by incorrect date format. The solution to this problem is to specify the date format correctly and use a suitable method for date conversion. Below are some common workarounds and sample code to help you troubleshoot Java date errors. Using SimpleDateFormat class SimpleDateFormat class is Java

Solution to mysql datetime error: 1. Change datetime to timestamp timestamp; 2. Upgrade MySQL to a higher version; 3. Execute the "ALTER USER 'root'@'localhost' IDENTIFIED BY 'root1' PASSWORD EXPIRE NEVER;" command That’s it.
