Difference between revisions of "Documentation/DevGuide/Basic/Date and Time Functions"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (FINAL VERSION FOR L10N)
m
 
Line 16: Line 16:
 
The Basic runtime function <code>CDateToIso</code> converts a date from the internal Basic date format to the required ISO date format. Since the string date format returned by the <code>Date</code> function is converted to the internal Basic date format automatically, <code>Date</code> can be used directly as an input parameter for <code>CDateToIso</code>:
 
The Basic runtime function <code>CDateToIso</code> converts a date from the internal Basic date format to the required ISO date format. Since the string date format returned by the <code>Date</code> function is converted to the internal Basic date format automatically, <code>Date</code> can be used directly as an input parameter for <code>CDateToIso</code>:
  
 +
<source lang="oobas">
 
   IsoDate = CDateToIso(Date)
 
   IsoDate = CDateToIso(Date)
 
   oTextField.setDate(IsoDate)
 
   oTextField.setDate(IsoDate)
 +
</source>
  
 
The runtime function <code>CDateFromIso</code> represents the reverse operation and converts a date from the ISO date format to the internal Basic date format.
 
The runtime function <code>CDateFromIso</code> represents the reverse operation and converts a date from the ISO date format to the internal Basic date format.
  
 +
<source lang="oobas">
 
   Dim aDate as date
 
   Dim aDate as date
 
   aDate = CDateFromIso(IsoDate)
 
   aDate = CDateFromIso(IsoDate)
 
+
</source>
 
Please see also [[Documentation/DevGuide/Basic/Programming Dialogs and Dialog Controls|Programming Dialogs and Dialog Controls]] in this context.
 
Please see also [[Documentation/DevGuide/Basic/Programming Dialogs and Dialog Controls|Programming Dialogs and Dialog Controls]] in this context.
  

Latest revision as of 09:44, 22 October 2009



OpenOffice.org Basic supports several Visual Basic compatible statements and functions to perform date and time calculations. The functions are DateSerial, DateValue, Day, Month, WeekDay, Year, Hour, Now, Second, TimeSerial, TimeValue, Date, Time, and Timer.

The function Date returns the current system date as a string and the function Time returns the current system time as a string. The other functions are not explained.

In the UNO/toolkit controls context there are two other functions. The date field control method com.sun.star.awt.XDateField:setDate() expects the date to be passed as a long value in a special ISO format and the com.sun.star.awt.XDateField:getDate() returns the date in this format.

The Basic runtime function CDateToIso converts a date from the internal Basic date format to the required ISO date format. Since the string date format returned by the Date function is converted to the internal Basic date format automatically, Date can be used directly as an input parameter for CDateToIso:

  IsoDate = CDateToIso(Date)
  oTextField.setDate(IsoDate)

The runtime function CDateFromIso represents the reverse operation and converts a date from the ISO date format to the internal Basic date format.

  Dim aDate as date
  aDate = CDateFromIso(IsoDate)

Please see also Programming Dialogs and Dialog Controls in this context.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages