The current system insertion time for Oracle, Db2, SqlServer, and MySQL databases.

Source: Internet
Author: User

The current system insertion time for Oracle, Db2, SqlServer, and MySQL databases.

I often encounter the following problems due to lack of knowledge about the time when the database is inserted into the system when I am working on a yibui Network Project:

1, java. SQL. SQLException: ORA-01861: Text and format strings do not match,
Cause: the retrieved system time type is incorrect. It should be 'invalid date '.

Next we will introduce the time when Oracle, Db2, SqlServer, and MySQL databases are inserted into the current system.

For example, a table has two fields: name and makedate.
1. oracle:
The system insertion time should be sysdate:
Insert into table (name, makedate) values ('test', sysdate );
2. Db2:
The system insertion time should be current timestamp and the makedate data type should be timestamp.
Insert into table (name, makedate) values ('test', current timestamp );
3. SqlServer:
The system insertion time should be GETDATE ()
Insert into table (name, makedate) values ('test', GETDATE ());
4. MySQL:
The system insertion time should be:
Now (): Use 'yyyy-mm-dd hh: mm: ss' to return the current date and time, which can be directly stored in the datetime field.
Curdate (): the format of 'yyyy-mm-dd' returns the date of today, which can be saved directly to the date field.
Insert into table (name, makedate) values ('test', now ());

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.