The date base in SQLite

Source: Internet
Author: User
Tags greenwich time zone local time sqlite

SQLite includes the following time/date functions:

DateTime () ......... ........ Date and time of generation

Date () ........ ............ Date generated

Time () ........ ............ Generation time

Strftime () ........ ......... Format the date and time generated by the above three functions


The usage of datetime () is:

DateTime (Date/time, modifier, modifier ...)

The syntax for date () and time () is the same as DateTime ().


In a time/Date function, you can use a string in the following format as a parameter:

Yyyy-mm-dd

Yyyy-mm-dd

hh:mm YYYY-MM-DD HH:MM:SS

Yyyy-mm-dd HH:MM:SS. Sss

hh:mm

HH:MM:SS

HH:MM:SS. Sss

Now

Where now is the time to produce the present.


Example (the time to write this note is October 17, 2006 8 o'clock in the evening to 10, test environment: SQLite 2.8.17,WINXP, Beijing Time):

Example 1. Select DateTime (' Now '); Result: 2006-10-17 12:55:54
Example 2. Select DateTime (' 2006-10-17 '); Result: 2006-10-17 12:00:00
Example 3. Select DateTime (' 2006-10-17 00:20:00 ', ' +1 hour ', ' -12 minute '); Result: 2006-10-17 01:08:00
Example 4. Select Date (' 2006-10-17 ', ' +1 Day ', ' +1 Year '); Results: 2007-10-18
Example 5. Select DateTime (' Now ', ' start of Year '); Result: 2006-01-01 00:00:00
Example 6. Select DateTime (' Now ', ' start of Month '); Result: 2006-10-01 00:00:00
Example 7. Select DateTime (' Now ', ' start of Day '); Result: 2006-10-17 00:00:00
Example 8. Select DateTime (' Now ', ' +10 hour ', ' start of day ', ' +10 Hour '); Result: 2006-10-17 10:00:00
Example 9. Select DateTime (' Now ', ' localtime '); Result: 2006-10-17 21:21:47
Example 10. Select DateTime (' Now ', ' +8 Hour '); Results: 2006-10-17 21:24:45 the +1 hour and -12 minute in example 3 indicate that a certain amount of time can be increased or decreased at the base time (the first parameter of the DateTime function).
The start of year in Example 5 represents the time of the beginning of the first day.
As can be seen from Example 8, although the 2nd parameter added 10 hours, but was the 3rd parameter "start of day" to zero the time to 00:00:00, then the 4th parameter on the basis of 00:00:00 to increase the time of 10 hours into 10:00:00.
Example 9 converts the Greenwich time zone to the cost of the time zone.
Example 10 converts the Greenwich time zone to the East eight zone.
The strftime () function converts date strings in YYYY-MM-DD HH:MM:SS format to other forms of strings. The syntax of Strftime () is strftime (format, date/time, modifier, modifier, ...) It can be formatted with the following symbols for the date and time:%d month, 01-31%f decimal form of seconds, SS. SSS%H hours, 00-23%j calculates the day of the year, 001-366%m month, 00-12%m minutes, 00-59%s from January 1, 1970 to present the number of seconds%s seconds, 00-59%w week, 0-6 (0 is Sunday)%w calculated One day belongs to the first week of the year, 01-53%Y year, YYYY percent percent percentile
Examples of the use of strftime () are as follows: Example 11. Select Strftime ('%y.%m.%d%h:%m:%s ', ' Now ', ' localtime ');  Results: 2006.10.17 21:41:09 Example 11 uses a dot as the date separator, and converts the time to the local time zone. Original address: http://blog.csdn.net/derryzhang/article/details/5033155

The date base in SQLite

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.