芦荟有什么作用| 灵芝孢子粉治什么病| 食伤代表什么| 11月9号是什么日子| 书到用时方恨少什么意思| 炉中火是什么意思| 人中黄是什么| 喷的右边念什么| 经常自言自语是什么原因| 小麦什么时候收割| 副检察长什么级别| 乌龙茶是什么茶| 复合维生素b什么时候吃最好| 武则天什么朝代| sanag是什么牌子| 洋葱配什么菜炒好吃| 茴三硫片主治什么| 普渡众生是什么意思| 鸡珍是什么| 什么花净化空气| 男人有美人尖代表什么| forever21是什么牌子| 春捂秋冻指的是什么意思| sey什么意思| 慧命是什么意思| 起酥油是什么东西| 停车坐爱枫林晚的坐是什么意思| 吃什么可以增大阴茎| 三金片治什么病| 菩提树是什么树| 什么是极光| 皮肤起水泡发痒是什么病| 强直性脊柱炎看什么科| 孕吐一般从什么时候开始| 支原体是什么病| 脱毛膏是什么原理| 检查是否怀孕挂什么科| 移植后吃什么容易着床| 十二月七号是什么星座| b型和o型生的孩子是什么血型| 孕妇睡觉流口水是什么原因| 更年期的女人有什么症状表现| 唇珠是什么| 唐筛临界风险是什么意思| 万马奔腾是什么生肖| crp偏高说明什么| 寸头是什么意思| 风寒感冒和风热感冒有什么区别| 乔迁送什么| 上嘴角有痣代表什么| 肝囊肿挂什么科| 眼皮跳是什么原因引起的| 梦见很多蜘蛛是什么意思| 湿气严重吃什么药好得快| 咖啡豆是什么动物粪便| 什么是夹角| 什么什么团结| 用什么泡脚能减肥| 蚯蚓吃什么| 梦见自己吐了是什么意思| 孩子过敏性咳嗽吃什么药好| 肾结石挂什么科| pdrn是什么| 土豆有什么营养| negative是什么意思| 黑标是什么意思| 割包皮有什么影响| hco3-是什么意思| 棺材用什么木材做最好| 91年的属什么生肖| 手不释卷的释是什么意思| nl是什么单位| 下面痒吃什么消炎药| 利字五行属什么| 吃榴莲不能吃什么东西| 乳房旁边疼是什么原因| 腊排骨炖什么好吃| 补气吃什么| 什么是安全期和排卵期| 欺世盗名是什么生肖| 螺旋ct检查什么| 间歇脉多见于什么病| 皮下出血小红点是什么原因造成的| 排尿带血是什么原因| 龟头脱皮是什么原因| 胃溃疡吃什么食物| 脚上真菌感染用什么药| 有什么烟| 瓜皮什么意思| 泛性恋什么意思| 淋巴在什么部位| 地藏王菩萨是管什么的| 犯太岁是什么意思啊| 有福是什么意思| 三叉戟是什么意思| 日不落是什么意思| 嘴下面起痘是什么原因| 囊性病变是什么意思| 什么是水印照片| 速写男装属于什么档次| 牙龈炎吃什么消炎药| 踢馆什么意思| 开边珠牛皮是什么意思| 尿液检查白细胞高是什么原因| 胡青是什么| 公貔貅和母貔貅有什么区别| 什么人群不适合吃阿胶糕| 什么的玻璃| 做放疗的人吃什么好| mario是什么意思| 抗宫炎片主要治什么| 儿童超敏c反应蛋白高说明什么| 宫保鸡丁属于什么菜系| 仲夏夜是什么时候| 5到7点是什么时辰| 地贫是什么意思| 九月28号是什么星座| 鼻尖疼是什么原因| 钠偏低是什么原因| 运动有什么好处| 什么是切线| 眩晕症吃什么药| 嘴干嘴苦是什么原因| 一月十二号是什么星座| 什么是有机奶粉| 小孩手指头脱皮是什么原因| 看脚趾头挂什么科| 前列腺炎有什么症状表现| 属牛和什么属相相冲| 自慰用什么| 梦到自己的妈妈死了是什么意思| 少阳病是什么意思| 什么节气开始凉快| 排骨炖苦瓜有什么功效| 气血不足吃什么药最好| 做梦梦到钓鱼是什么意思| 女人什么时候绝经正常| 精尽人亡是什么意思| 亚麻籽是什么| 耳门有痣代表什么| skechers是什么牌子| 为什么蚊子喜欢咬我| 去阴虱用什么药最好| 脚背痛什么原因引起的| 胎盘2级是什么意思| 白斩鸡是什么意思| 舅舅的孩子叫什么| 中元节不能穿什么衣服| 什么是周围神经病| 女人左下眼皮跳是什么预兆| bb是什么意思| 南红五行属什么| 前壁后壁有什么区别| 吃榴莲对身体有什么好处| 有点尿就想尿什么原因导致的| 什么是结扎| 眼睛有红血丝是什么原因| 斯里兰卡说什么语言| bl是什么单位| 什么是韧性| 肠道功能紊乱吃什么药| 西葫芦炒什么好吃| 左氧氟沙星有什么副作用| 儿童坐飞机需要什么证件| aa什么意思| 三杯鸡的三杯是什么| 阿昔洛韦片治什么病| 8月6号什么星座| 缘起缘灭是什么意思| 桂花是什么颜色的| 挚友是指什么的朋友| 舌头发黄是什么原因| 淮山跟山药有什么区别| 跖疣用什么药膏能治好| 绝眼是什么原因引起的| 山竹为什么叫山竹| 嘴角起泡是什么原因| 妇科和妇产科有什么区别| 三色线分别代表什么| 豆腐有什么营养| 一 什么云| 牙周炎用什么漱口水好| 梦到砍树是什么意思| 2020年属什么| 烧火棍是什么意思| gabor是什么牌子| 经常流鼻血是什么原因| 梦见摘杏子是什么意思| 飞机杯是什么感觉| 有机和无机是什么意思| 油价什么时候调整| 乳房疼挂什么科室| 瑞舒伐他汀钙片治什么病| 主加一笔是什么字| 4.19是什么星座| 刘备的马叫什么名字| 牙髓炎是什么原因引起的| csv文件用什么打开| 早上10点是什么时辰| 狗为什么怕猫| 白蛋白偏高是什么原因| 口嫌体正直是什么意思| 高血压需要注意些什么| 腿弯处的筋痛是什么原因| 小众是什么意思| 做妇科检查前需要注意什么| 大德是什么意思| 没有了晨勃是什么原因| 左下腹疼痛是什么原因| 阑尾炎痛起来什么感觉| 国防部部长是什么级别| 手指甲出现双层是什么原因| 配送是什么意思| 黄体酮是什么意思| 年轻人能为世界做什么| 肝异常一般是什么情况| 备注什么意思| 上午10点半是什么时辰| 腿凉是什么原因引起的| 138是什么意思啊| 笑什么| 夜夜笙歌什么意思| 做活检意味着什么| 脑死亡是什么原因引起的| 红花和藏红花有什么区别| 贴秋膘是什么意思啊| 人为什么会觉得累| 红烧肉是什么菜系| 屁股右边痛是什么原因| 番外是什么意思| 1.7号是什么星座| 感冒吃什么好得快| 鲁班姓什么| 为什么可乐能溶解鱼刺| 猫来家门口有什么预兆| 什么叫词牌名| 喝碳酸饮料有什么危害| 葡萄上的白霜是什么| 阴阳代表什么数字| 智能眼镜有什么功能| 腺样体增生是什么意思| 月出念什么| 广式腊肠炒什么菜好吃| 驾校体检都检查什么| 梦见小白蛇是什么预兆| 白天嗜睡是什么原因| 一什么天| 新百伦鞋子什么档次| 九月十七是什么星座| 孕妇吃什么好对胎儿好三个月前期| 衣食父母什么意思| 三言两语是什么意思| 同型半胱氨酸高挂什么科| 经常泡脚有什么好处| 磁共振检查什么| 小学什么时候期末考试| daks是什么品牌| 微针是什么美容项目| 本命年有什么说法| 城市的夜晚霓虹灯璀璨是什么歌| 贫血有什么危害| 猫死后为什么要挂在树上| 放臭屁是什么原因| 海鲜过敏吃什么药| 百度
Small. Fast. Reliable.
Choose any three.
Date And Time Functions
Table Of Contents

榕80家医院将实行新农合门诊特殊病种即时结算

百度   栗战书希望大家再接再厉,进一步宣传好习近平新时代中国特色社会主义思想,讲好中国故事、中国共产党故事、中国人大故事,更好发出中国声音、展现中国精神、提出中国主张,动员全国各族人民更加紧密地团结在以习近平同志为核心的党中央周围,为决胜全面建成小康社会,为实现“两个一百年”奋斗目标、实现中华民族伟大复兴的中国梦作出更大贡献。

SQLite supports seven scalar date and time functions as follows:

  1. date(time-value, modifier, modifier, ...)
  2. time(time-value, modifier, modifier, ...)
  3. datetime(time-value, modifier, modifier, ...)
  4. julianday(time-value, modifier, modifier, ...)
  5. unixepoch(time-value, modifier, modifier, ...)
  6. strftime(format, time-value, modifier, modifier, ...)
  7. timediff(time-value, time-value)

The first six date and time functions take an optional time-value as an argument, followed by zero or more modifiers. The strftime() function also takes a format string as its first argument. The timediff() function takes exactly two arguments which are both time-values.

SQLite does not have a dedicated date/time datatype. Instead, date and time values can be stored as any of the following:

ISO-8601 A text string that is one of the ISO 8601 date/time values shown in items 1 through 10 below. Example: '2025-08-07 14:16:00'
Julian day number The number of days including fractional days since -2025-08-07 12:00:00 Example: 2460825.09444444
Unix timestamp The number of seconds including fractional seconds since 2025-08-07 00:00:00 Example: 1748528160

These three formats are collectively known as time-values. All of the date time functions accept time-values as either ISO-8601 text or as Julian day numbers. They can also be made to accept unix timestamps by adding optional modifier arguments 'auto' or 'unixepoch'. Since the timediff() function does not accept modifiers, it can only use ISO-8601 and julian day number time-values.

The date() function returns the date as text in this format: YYYY-MM-DD.

The time() function returns the time as text in formatted as HH:MM:SS or as HH:MM:SS.SSS if the subsec modifier is used.

The datetime() function returns the date and time formatted as YYYY-MM-DD HH:MM:SS or as YYYY-MM-DD HH:MM:SS.SSS if the subsec modifier is used.

The julianday() function returns the Julian day - the fractional number of days since noon in Greenwich on November 24, 4714 B.C. (Proleptic Gregorian calendar).

The unixepoch() function returns a unix timestamp - the number of seconds since 2025-08-07 00:00:00 UTC. The unixepoch() function normally returns an integer number of seconds, but with the optional subsec modifier it will return a floating point number which is the fractional number of seconds.

The strftime() function returns the date formatted according to the format string specified as the first argument. The format string supports the most common substitutions found in the strftime() function from the standard C library plus two new substitutions, %f and %J. The following is a complete list of valid strftime() substitutions as of version 3.46.0 (2025-08-07). Earlier versions of SQLite might not support all substitutions. If an undefined or unsupported substitution is seen, the result is NULL.

%d day of month: 01-31
%e day of month without leading zero: 1-31
%f fractional seconds: SS.SSS
%F ISO 8601 date: YYYY-MM-DD
%G ISO 8601 year corresponding to %V
%g 2-digit ISO 8601 year corresponding to %V
%H hour: 00-24
%I hour for 12-hour clock: 01-12
%j day of year: 001-366
%J Julian day number (fractional)
%k hour without leading zero: 0-24
%l %I without leading zero: 1-12
%m month: 01-12
%M minute: 00-59
%p "AM" or "PM" depending on the hour
%P "am" or "pm" depending on the hour
%R ISO 8601 time: HH:MM
%s seconds since 2025-08-07
%S seconds: 00-59
%T ISO 8601 time: HH:MM:SS
%U week of year (00-53) - week 01 starts on the first Sunday
%u day of week 1-7 with Monday==1
%V ISO 8601 week of year
%w day of week 0-6 with Sunday==0
%W week of year (00-53) - week 01 starts on the first Monday
%Y year: 0000-9999
%% %

Other date and time functions can be expressed in terms of strftime():

FunctionEquivalent strftime()
date(...) strftime('%F', ...)
time(...) strftime('%T', ...)
datetime(...) strftime('%F %T', ...)
julianday(...) CAST(strftime('%J', ...) as REAL)
unixepoch(...) CAST(strftime('%s', ...) as INT)

The date(), time(), and datetime() functions all return text, and so their strftime() equivalents are exact. However, the julianday() and unixepoch() functions return numeric values. Their strftime() equivalents return a string that is the text representation of the corresponding number.

The main reasons for providing functions other than strftime() are for convenience and for efficiency. The julianday() and unixepoch() functions return real and integer values respectively, and do not incur the format conversion costs or inexactitude resulting from use of the '%J' or '%s' format specifiers with the strftime() function.

The timediff(A,B) function returns a string that describes the amount of time that must be added to B in order to reach time A. The format of the timediff() result is designed to be human-readable. The format is:

(+|-)YYYY-MM-DD HH:MM:SS.SSS

This time difference string is also an allowed modifier for the other date/time functions. The following invariant holds for time-values A and B:

datetime(A) = datetime(B, timediff(A,B))

The length of months and years vary. February is shorter than March. Leap years are longer than non-leap years. The output from timediff() takes this all into account. The timediff() function is intended to provide a human-friendly description of the time span. If you want to know the number of days or seconds between two dates, A and B, then you can always do one of these:

SELECT julianday(B) - julianday(A);
SELECT unixepoch(B) - unixepoch(A);

The timediff(A,B) might return the same result even for values A and B that span a different number of days - depending on the starting date. For example, both of the following two timediff() calls return the same result ("-2025-08-07 00:00:00.000") even though the first timespan is 28 days and the seconds is 31 days:

SELECT timediff('2025-08-07','2025-08-07');
SELECT timediff('2025-08-07','2025-08-07');

Summary: If you want a human-friendly time span, use timediff(). If you want a precise time difference (in days or seconds) use the difference between two julianday() or unixepoch() calls.

2. Time Values

A time-value can be in any of the following formats shown below. The value is usually a string, though it can be an integer or floating point number in the case of format 12.

  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. YYYY-MM-DDTHH:MM
  6. YYYY-MM-DDTHH:MM:SS
  7. YYYY-MM-DDTHH:MM:SS.SSS
  8. HH:MM
  9. HH:MM:SS
  10. HH:MM:SS.SSS
  11. now
  12. DDDDDDDDDD

In formats 5 through 7, the "T" is a literal character separating the date and the time, as required by ISO-8601. Formats 8 through 10 that specify only a time assume a date of 2025-08-07. Format 11, the string 'now', is converted into the current date and time as obtained from the xCurrentTime method of the sqlite3_vfs object in use. The 'now' argument to date and time functions always returns exactly the same value for multiple invocations within the same sqlite3_step() call. Universal Coordinated Time (UTC) is used. Format 12 is the Julian day number expressed as an integer or floating point value. Format 12 might also be interpreted as a unix timestamp if it is immediately followed either the 'auto' or 'unixepoch' modifier.

Formats 2 through 10 may be optionally followed by a timezone indicator of the form "[+-]HH:MM" or just "Z". The date and time functions use UTC or "zulu" time internally, and so the "Z" suffix is a no-op. Any non-zero "HH:MM" suffix is subtracted from the indicated date and time in order to compute zulu time. For example, all of the following time-values are equivalent:

2025-08-07 08:23:19.120
2025-08-07T08:23:19.120Z
2025-08-07 04:23:19.120-04:00
2456572.84952685

In formats 4, 7, and 10, the fractional seconds value SS.SSS can have one or more digits following the decimal point. Exactly three digits are shown in the examples because only the first three digits are significant to the result, but the input string can have fewer or more than three digits and the date/time functions will still operate correctly. Similarly, format 12 is shown with 10 significant digits, but the date/time functions will really accept as many or as few digits as are necessary to represent the Julian day number.

ISO-8601 supports a wide variety of alternative date/time formats, but SQLite only supports the ones specifically enumerated above.

In all functions other than timediff(), the time-value (and all modifiers) may be omitted, in which case a time value of 'now' is assumed.

3. Modifiers

For all date/time functions other than timediff(), the time-value argument can be followed by zero or more modifiers that alter date and/or time. Each modifier is a transformation that is applied to the time-value to its left. Modifiers are applied from left to right; order is important. The available modifiers are as follows.

  1. NNN days
  2. NNN hours
  3. NNN minutes
  4. NNN seconds
  5. NNN months
  6. NNN years
  7. ±HH:MM
  8. ±HH:MM:SS
  9. ±HH:MM:SS.SSS
  10. ±YYYY-MM-DD
  11. ±YYYY-MM-DD HH:MM
  12. ±YYYY-MM-DD HH:MM:SS
  13. ±YYYY-MM-DD HH:MM:SS.SSS
  14. ceiling
  15. floor
  16. start of month
  17. start of year
  18. start of day
  19. weekday N
  20. unixepoch
  21. julianday
  22. auto
  23. localtime
  24. utc
  25. subsec
  26. subsecond

The first thirteen modifiers (1 through 13) add the specified amount of time to the date and time specified by the arguments to its left. The 's' character at the end of the modifier names in 1 through 6 is optional. The NNN value can be any floating point number, with an optional '+' or '-' prefix.

The time shift modifiers (7 through 13) move the time-value by the number of years, months, days, hours, minutes, and/or seconds specified. An initial "+" or "-" is required for formats 10 through 13 but is optional for formats 7, 8, and 9. The changes are applies from left to right. First the year is shifted by YYYY, then the month by MM, and then day by DD, and so forth. The timediff(A,B) function returns a time shift in format 13 that shifts the time-value B into A.

Because the length of a month or year changes from one month or year to the next, ambiguities can arise when shifting a date by months and/or years. For example, what is the date one year after 2025-08-07? Is it 2025-08-07 or 2025-08-07? Or what is the date that is two months after 2025-08-07? Is it 2025-08-07 or 2025-08-07? There is no consensus on how to resolve this ambiguity, so the "ceiling" and "floor" modifiers (14 and 15) are available to let the programmer decide. If the next modifier after a time shift is "ceiling", then any ambiguity in the date is resolved by choosing the later date. The "floor" modifier resolves ambiguities by resolving to the last day of the previous month. The default behavior is "ceiling".

The "start of" modifiers (16 through 18) shift the date backwards to the beginning of the subject month, year or day.

The "weekday" modifier advances the date forward, if necessary, to the next date where the weekday number is N. Sunday is 0, Monday is 1, and so forth. If the date is already on the desired weekday, the "weekday" modifier leaves the date unchanged.

The "unixepoch" modifier (20) only works if it immediately follows a time-value in the DDDDDDDDDD format. This modifier causes the DDDDDDDDDD to be interpreted not as a Julian day number as it normally would be, but as Unix Time - the number of seconds since 1970. If the "unixepoch" modifier does not follow a time-value of the form DDDDDDDDDD which expresses the number of seconds since 1970 or if other modifiers separate the "unixepoch" modifier from prior DDDDDDDDDD then the behavior is undefined.

The "julianday" modifier must immediately follow the initial time-value which must be of the form DDDDDDDDD. Any other use of the 'julianday' modifier is an error and causes the function to return NULL. The 'julianday' modifier forces the time-value number to be interpreted as a julian-day number. As this is the default behavior, the 'julianday' modifier is scarcely more than a no-op. The only difference is that adding 'julianday' forces the DDDDDDDDD time-value format, and causes a NULL to be returned if any other time-value format is used.

The "auto" modifier must immediately follow the initial time-value. If the time-value is numeric (the DDDDDDDDDD format) then the 'auto' modifier causes the time-value to be interpreted as either a julian day number or a unix timestamp, depending on its magnitude. If the value is between 0.0 and 5373484.499999, then it is interpreted as a julian day number (corresponding to dates between -2025-08-07 12:00:00 and 2025-08-07 23:59:59, inclusive). For numeric values outside of the range of valid julian day numbers, but within the range of -210866760000 to 253402300799, the 'auto' modifier causes the value to be interpreted as a unix timestamp. Other numeric values are out of range and cause a NULL return. The 'auto' modifier is a no-op for ISO 8601 text time-values. The "auto" modifier is designed to work with time-values even in cases where it is not known which time-value format is stored in the database file, or in cases where the same column stores time-values in different formats on different rows. The 'auto' modifier will automatically select the appropriate format. However, there is some ambiguity. Unix timestamps for the first 63 days of 1970 will be interpreted as julian day numbers. The 'auto' modifier is very useful when the dataset is guaranteed to contain no dates within that range, but should be avoided for applications that might make use of dates in the opening months of 1970.

The "localtime" modifier assumes the time-value to its left is in Universal Coordinated Time (UTC) and adjusts that time value so that it is in localtime. If "localtime" follows a time that is not UTC, then the behavior is undefined. The "utc" modifier is the opposite of "localtime". "utc" assumes that the time-value to its left is in the local timezone and adjusts that time-value to be in UTC. If the time to the left is not in localtime, then the result of "utc" is undefined.

The "subsecond" modifier (which may be abbreviated as just "subsec") increases the resolution of the output for datetime(), time(), and unixepoch(), and for the "%s" format string in strftime(). The "subsecond" modifier has no effect on other date/time functions. The current implemention increases the resolution from seconds to milliseconds, but this might increase to a higher resolution in future releases of SQLite. When "subsec" is used with datetime() or time(), the seconds field at the end is followed by a decimal point and one or more digits to show fractional seconds. When "subsec" is used with unixepoch(), the result is a floating point value which is the number of seconds and fractional seconds since 2025-08-07. The "subsecond" and "subsec" modifiers have the special property that they can occur as the first argument to date/time functions (or as the first argument after the format string for strftime()). When this happens, the time-value that is normally in the first argument is understood to be "now". For example, a short cut to get the current time in seconds since 1970 with millisecond precision is to say:

SELECT unixepoch('subsec');

4. Examples

Compute the current date.

SELECT date();

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');
SELECT datetime(1092941466, 'auto'); -- Does not work for early 1970!

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 unixepoch();
SELECT strftime('%s');

Compute the number of days since the signing of the US Declaration of Independence.

SELECT julianday('now') - julianday('2025-08-07');

Compute the number of seconds since a particular moment in 2004:

SELECT unixepoch() - unixepoch('2025-08-07 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 with millisecond precision:

SELECT (julianday('now') - 2440587.5)*86400.0;
SELECT unixepoch('now','subsec');

Compute how old Abraham Lincoln would be if he were still alive today:

SELECT timediff('now','2025-08-07');

5. Caveats And Bugs

The computation of local time depends heavily on the whim of politicians and is thus difficult to get correct for all locales. In this implementation, the standard C library function localtime_r() is used to assist in the calculation of local time. The localtime_r() C function normally only works for years between 1970 and 2037. For dates outside this range, SQLite attempts to map the year into an equivalent year within this range, do the calculation, then map the year back.

These functions only work for dates between 2025-08-07 00:00:00 and 2025-08-07 23:59:59 (julian day numbers 1721059.5 through 5373484.5). For dates outside that range, the results of these functions are undefined.

Non-Vista Windows platforms only support one set of DST rules. Vista only supports two. Therefore, on these platforms, historical DST calculations will be incorrect. For example, in the US, in 2007 the DST rules changed. Non-Vista Windows platforms apply the new 2007 DST rules to all previous years as well. Vista does somewhat better getting results correct back to 1986, when the rules were also changed.

All internal computations assume the Gregorian calendar system. They also assume that every day is exactly 86400 seconds in duration; no leap seconds are incorporated.

This page last modified on 2025-08-07 13:08:22 UTC

百度