Friday, August 12, 2016

How to use the DATEVALUE Function (WS, VBA)

Description

The Microsoft Excel DATEVALUE function returns the serial number of a date.

Syntax

The syntax for the DATEVALUE function in Microsoft Excel is:
DATEVALUE( date )

Parameters or Arguments

date
A string representation of a date.

Applies To

  • Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000

Type of Function

  • Worksheet function (WS)
  • VBA function (VBA)

Example (as Worksheet Function)

Let's look at some Excel DATEVALUE function examples and explore how to use the DATEVALUE function as a worksheet function in Microsoft Excel:
Microsoft Excel
Based on the Excel spreadsheet above, the following DATEVALUE examples would return:
=DateValue(A1)
Result: 41153

=DateValue(A2)
Result: 41152

=DateValue(A3)
Result: 41501

=DateValue("30-Nov-2012")
Result: 41243

Example (as VBA Function)

The DATEVALUE function can be used in VBA code in Microsoft Excel.
Let's look at some Excel DATEVALUE function examples and explore how to use the DATEVALUE function in Excel VBA code:
Dim LDate As Date

LDate = DateValue("May 15, 2012")
In this example, the variable called LDate would now contain the value of 5/15/2012.