This paper mainly explains the analysis and summarization of time function in SQLite and gives the use case. The examples given in this article are all tested.
SQLite Time/Date function type:
1. DateTime (): Date and time of production
2, Date (): Production dates
3:, Time (): Generation
4, Strftime (): The above three functions generated by the date and time to format
SQLite Time/Date function usage:
1, the use of DateTime () is: datetime (date/time, modifier, modifier ...)
2, date () and time () are the same syntax as DateTime ().
3. The strftime () function converts a date string in the YYYY-MM-DD HH:MM:SS format to another form of string.
The syntax of Strftime () is strftime (format, date/time, modifier, modifier, ...)
SQLite time/Date function format:
DateTime (), date (), and time () can be used as a parameter in the Date/Date function as a string in the following format:
1, YYYY-MM-DD
2, Yyyy-mm-dd hh:mm
3, Yyyy-mm-dd HH:MM:SS
4, Yyyy-mm-dd HH:MM:SS. Sss
5, hh:mm
6, HH:MM:SS
7, HH:MM:SS. Sss
8, now which is the time to produce the present.
Strftime () You can format dates and times with the following symbols:
%d months, 01-31
%f decimal form of the second, SS. Sss
%H hours, 00-23
%j calculated that one day was the first of the year, 001-366
%m month, 00-12
%m minutes, 00-59
%s number of seconds from January 1, 1970 to today
%s seconds, 00-59
%w Week, 0-6 (0 is Sunday)
%w the first few weeks of the year, 01-53
%Y years, YYYY
Percent percent%
SQLite Time/Date function use case:
Example 1. Select DateTime (' Now '); results: 2012-05-16 03:23:21
Example 2. Select datetime (' 2012-05-16 '); results: 2012-05-16 00:00:00
Example 3. Select DateTime (' 2012-05-16 00:20:00 ', ' 3 hour ', ' -12 minute '); Results: 2012-05-16 03:08:00
Description: 3 hour and -12 minute indicate that the first parameter of the DateTime function can be increased or decreased for a certain time on the base time.
Example 4. Select Date (' 2012-05-16 ', ' 1 day ', ' 1 year '); Results: 2013-05-17
Example 5. Select DateTime (' Now ', ' start of Year '); Results: 2012-01-01 00:00:00
Description: The start of year represents the beginning of a period.
Example 6. Select DateTime (' Now ', ' start of Month '); Results: 2012-05-01 00:00:00
Example 7. Select DateTime (' Now ', ' start of '); Results: 2012-05-16 00:00:00
Example 8. Select DateTime (' Now ', ' hour ', ' Start ', ' hour '); Results: 2012-05-16 10:00:00
Note: Although the 2nd parameter plus 10 hours, but by the 3rd parameter "Start Day" to the time to zero 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. Select DateTime (' Now ', ' localtime '); Result: DateTime (' Now ', ' localtime ') 2012-05-16 11:52:20
Description: Greenwich time zone conversion cost time zone
Example 10. Select DateTime (' Now ', ' 8 Hour '); results: 2012-05-16 11:53:41
Description: Convert Greenwich time zone to East eight.
Example 11. select strftime ('%y.%m.%d%h:%m:%s ', ' Now ', ' localtime '); Result: 2012.05.16 11:59:56