Text Documents (Writer)
HTML Documents (Writer Web)
Spreadsheets (Calc)
Presentations (Impress)
Drawings (Draw)
Database Functionality (Base)
Formulae (Math)
Charts and Diagrams
Macros and Scripting
Office Installation
Common Help Topics
OneOffice Logo

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.

Syntax:


  DateValue(date As String)

Parameters:

date: A string that contains the date that will be converted to a Date object.

The string passed to DateValue must be expressed in one of the date formats defined by your locale setting (see Tools - Options - Language Settings - Languages) or using the ISO date format "yyyy-mm-dd" (year, month and day separated by hyphens).

Return value:

Date.

Error codes:

5 Invalid procedure call

Example:


  Sub ExampleDateValue
      Dim aDate As Date
      aDate = DateValue("2021-12-20")
      ' Prints the localised date
      MsgBox aDate
      ' Extracts the year, month and day from the date object
      MsgBox Year(aDate)
      MsgBox Month(aDate)
      MsgBox Day(aDate)
      ' Prints the numeric value corresponding to the date (as Long type)
      MsgBox CLng(aDate)
  End Sub