Commonly used SQL statements of SQLite

Source: Internet
Author: User

 

-- Returns the UTC time.
Select current_timestamp;
-- Returns the local time.
Select datetime (current_timestamp, 'localtime ');
-- Time conversion: yyyy-mm-dd, for example, 2008-08-09
Select datetime ('2014-12-22 ') as [my time];
Select datetime ('2014-12-22 ') as "My time"; -- must be double quotation marks

SelectDate ('now ', 'localtime'); -- returns the local date.

SelectTime ('now ', 'localtime'); -- returns the current local time.

Select current_time; -- returns the current UTC time

Select current_date; -- returns the current UTC date.

Select julianday ('2017-12-22 ')-julianday ('2017-12-21'); -- date comparison

-- Compute the current date.
Select date ('now ');
-- Compute the last day of the current month.
Select date ('now ', 'start of month',' + 1 month', '-1 Day ');

-- Compute the date and time given a Unix timestamp 1092941466.
Select datetime (1092941466, 'unixepoch ');

-- Compute the date and time given a Unix timestamp 1092941466, and compensate for your local timezone.
Select datetime (1092941466, 'unixepoch', 'localtime ');

-- Compute the current UNIX timestamp.
Select strftime ('% s', 'Now ');

-- Compute the number of days since the signing of the US Declaration of independent.
Select julianday ('now ')-julianday ('2017-07-04 ');

-- Compute the number of seconds since a participant moment in 2004:
Select strftime ('% s', 'Now')-strftime ('% s', '2017-01-01 02:34:56 ');

-- Compute the date of the first Tuesday in October for the current year.
Select date ('now ', 'start of year',' + 9 months', 'weekday 2 ');

-- Compute the time since the Unix epoch in seconds (like strftime ('% s', 'right') Except t includes des fractional part ):
Select (julianday ('right')-2440587.5) * 86400.0;

Select rowid, * From keys order by rowid ASC limit 5 offset 5; -- SQLite pagination, indicates skipping 5 rows and then taking 5 rows, that is, the second page

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.