SQLite default current time

Source: Internet
Author: User

In SQL Server, when creating a table, you can specify the default value as the current time (that is, the default timestamp is used when the record is generated) for the Time column ). For example:

Create Table log (content varchar (256), logtime datetime default getdate ())

But how to implement it in SQLite? Check the document and find that SQLite does not have the getdate () function, but its built-in functions include datetime (). So can we implement the default timestamp according to the following statement:

Create Table log (content varchar (256), logtime datetime default datetime ('now '))

The answer is no. A syntax error is prompted. So how should we declare it? As follows:

Create Table log (content varchar (256), logtime timestamp default current_timestamp)

This can achieve the effect, but the default time is based on the GMT standard time, so it will be 8 hours earlier in China. To solve this problem, we can declare:

Create Table log (content varchar (256), logtime timestamp default (datetime ('now ', 'localtime ')))

Test, everything is normal :)

Related Article

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.