VBA Function: DateValue

The VBA function DateValue converts a string to a date, accepting different date formats.

Usage:

DateValue(text)


Example of Usage

Using the DateValue function to convert different strings to dates:

Sub example()

    MsgBox DateValue("10/30/2026") 'Returns: 10/30/2026
    MsgBox DateValue("10/30/26") 'Returns: 10/30/2026
    MsgBox DateValue("2026-10-30") 'Returns: 10/30/2026
    MsgBox DateValue("10 30 2026") 'Returns: 10/30/2026
    MsgBox DateValue("30 October 2026") 'Returns: 10/30/2026
    MsgBox DateValue("October 30, 2026") 'Returns: 10/30/2026
    MsgBox DateValue("Oct-30-2026") 'Returns: 10/30/2026
    MsgBox DateValue("10/30/2026 21:30:00") 'Returns: 10/30/2026

End Sub

In this example, all the strings return the same date.