转换日期值

以下函数用于将日期转换为可计算的数字或者将数字转换为日期。

DateSerial Function

Returns a Date value for a specified year, month, and day.

DateValue Function

Returns a Date object from a string representing a date.

The returned object is represented internally as a single numeric value corresponding to the specified date. This value can be used to calculate the number of days between two dates.

Day 函数

根据「DateSerial」或「DateValue」生成的顺序日期数,返回表示某个月中某一天的数值。

Month 函数

根据 DateSerial 或 DateValue 函数生成的顺序日期,返回某一年份中的月份。

WeekDay Function

This function returns the number corresponding to the weekday represented by a serial date number that is generated by the DateSerial or the DateValue functions.

Year 函数

根据 DateSerial 或 DateValue 函数生成的顺序日期数返回年份。

CDateToIso 函数

返回以ISO格式表示的,由 DateSerial,DateValue 或 CDateFromIso 函数生成的日期数字序列对应的的无分隔符的日期。

年份至少包含四位数字,如果输入年份的绝对值小于1000则会在数字前加上零;如果输入的日期表示公元前一年 (BCE前一年),则可以带有负号并带有负号;如果绝对值大于9999,则为四位数。返回的格式化字符串可以在「-327680101」至「327671231」范围内。

批注图标

小于 100 以及大于 9999 的年份从 LibreOffice 5.4 版本开始已被支持。


CDateFromIso 函数

返回 ISO 格式日期的字符对应的内部日期值 ( 年月日 或 年-月-日)。

年份必须包含两个 (仅支持YYMMDD格式,不支持兼容性分隔符) 或至少四位数字。 如果绝对值小于1000,则必须给出四位数添加零;如果输入的日期表示公元年 (BCE) 之前的一年,就可以用负数 (在年份前添加负号);如果绝对值大于9999,则该数字可以超过四位 。格式化的字符串可以在「-327680101」至「327671231」或「-32768-01-01」至「32767-12-31」的范围内。

无效的日期会导致错误。 填写0是不接受的,公元前最后一天为-0001-12-31,次日 (即公元1年第一天) 为0001-01-01。 1582-10-15之前的日期是在格雷戈里的日历中的。

提示图标

将日期序列号转换为可打印的字符串时 (例如对于Print或MsgBox命令),将使用区域设置的默认日历,并且在1582-10-15边界日期可能切换到Julian日历,这可能会导致显示的日期与预期的不同。可以使用CDateToIso 函数将日期数字转换为公历日历中的字符串表示。


批注图标

自 LibreOffice 5.3.4 ,已经支持 年-月-日 (带分隔符的) 格式。自 LibreOffice 5.4 ,如果不是运行在 VBA 兼容模式,那么小于 100 或大于 9999 的年份也受到支持。


CDateToUnoDate 函数

以 UNO com.sun.star.util.Date 结构体返回日期。

CDateFromUnoDate 函数

将 UNO com.sun.star.util.Date struct 转换为日期值。

CDateToUnoDateTime 函数

将日期的时间部分返回为 UNO com.sun.star.util.DateTime struct。

CDateFromUnoDateTime 函数

将 UNO com.sun.star.util.DateTime struct 转换为日期值。

DateAdd 函数

Adds a date or time interval to a given date a number of times and returns the resulting date.

DateDiff 函数

Returns the number of date or time intervals between two given date values.

DatePart 函数

DatePart 函数可返回某个日期的指定部分。

请支持我们!