22.01.2015 Views

OpenOffice.org Macros Explained - LibreOffice-NA.US

OpenOffice.org Macros Explained - LibreOffice-NA.US

OpenOffice.org Macros Explained - LibreOffice-NA.US

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

second correspond to the numbers 1/24, 1/(24 * 60), and 1/(24 * 60 * 60), respectively. The date functions<br />

supported by OOo Basic are introduced in Table 10 and fully discussed later.<br />

Listing 15. Demonstrate date variables.<br />

Sub ExampleDateType<br />

Dim tNow As Date, tToday As Date<br />

Dim tBirthDay As Date<br />

tNow = Now()<br />

tToday = Date()<br />

tBirthDay = DateSerial(1776, 7, 4)<br />

Print "Today = " & tToday<br />

Print "Now = " & tNow<br />

Print "A total of " & (tToday - tBirthDay) &_<br />

" days have passed since " & tBirthDay<br />

End Sub<br />

Negative numbers are valid and correspond to dates before December 30, 1899. January 1, 0001,<br />

corresponds to the floating-point number -693,595. Continuing backward produces dates that are B.C.<br />

(Before Christ, sometimes also referred to as B.C.E., meaning Before the Christian Era, or Before the<br />

Common Era) rather than A.D. (Anno Domini). A thorough discussion of date handling is presented later.<br />

Table 10. Functions and subroutines related to dates and times.<br />

Function Type Description<br />

CDate(expression) Date Convert a number or string to a date.<br />

CDateFromIso(string) Date Convert to a date from an ISO 8601 date representation.<br />

CDateToIso(date) String Convert a date to an ISO 8601 date representation.<br />

Date() String Return the current date as a String.<br />

DateSerial(yr, mnth, day) Date Create a date from component pieces: Year, Month, Day.<br />

DateValue(date) Date Extract the date from a date/time value by truncating the decimal portion.<br />

Day(date) Integer Return the day of the month as an Integer from a Date value.<br />

GetSystemTicks() Long Return the number of system ticks as a Long.<br />

Hour(date) Integer Return the hour as an Integer from a Date value.<br />

IsDate(value) Boolean Is this a date<br />

Minute(date) Integer Return the minute as an Integer from a Date value.<br />

Month(date) Integer Return the month as an Integer from a Date value.<br />

Now() Date Return the current date and time as a Date object.<br />

Second(date) Integer Return the seconds as an Integer from a Date value.<br />

Time() String Return the time as a String.<br />

Timer() Date Return the number of seconds since midnight as a Date. Convert to a Long.<br />

TimeSerial(hour, min, sec) Date Create a date from component pieces: Hours, Minutes, Seconds.<br />

WeekDay(date) Integer Return the integer 1 through 7, corresponding to Sunday through Saturday.<br />

Year(date) Integer Return the year as an Integer from a Date value.<br />

40

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!