VBA DateValue Function

Written by

Editorial Team

Reviewed by

Steve Rynearson

Last updated on July 19, 2021

DateValue Description

Returns the serial number of a date.

Simple DateValue Examples

Here is a simple DateValue example:

Sub DateValue_Example()
    MsgBox DateValue("Feb 12, 2019")
End Sub

This code will return 02/12/2019.

Following examples will have same result.

DateValue("2 12 2019")
DateValue("February 12, 2019")

If date is a string that includes only numbers separated by valid date seperators(” “, “/”, “,”, “-“), DateValue recognizes the order for month, day, and year according to the Short Date format that you specified for your system. DateValue also recognizes unambiguous dates that contain month names, either in long or abbreviated form.

If the year part of date is omitted, DateValue uses the current year from your computer’s system date.

If the date argument includes time information, DateValue doesn’t return it. However, if date includes invalid time information (such as “37:69”), an error occurs.


DateValueAdd Syntax

In the VBA Editor, you can type  “DateValue(” to see the syntax for the DateValue Function:

The DateAdd function contains an argument:

Date: A string of text representing a date (ex. “January 1, 2021”)


Examples of Excel VBA DateValue Function

You can reference a cell containing a date:

Sub DateValue_ReferenceDates_Cell()
    MsgBox DateValue(Range("C2").Value)
End Sub

This will return 01/02/2019.

The DateValue recognizes the month, day, and year for a valid date string.


Result: 06/15/2019



VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as

Learn More!

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples