DateValue - VBScript


Overview

DateValue converts a string expression representing a date and/or time into a Date.

Syntax

DateValue(string)

| Parameter | Description |
|—|—|
| string | String to convert to a date. |

Options/Flags

None.

Examples

Dim dt
dt = DateValue("2/22/2023") 
'Returns: #February 22, 2023#

dt = DateValue("Feb 22, 23") 
'Returns: #February 22, 2023#

dt = DateValue("2023-02-22") 
'Returns: #February 22, 2023#

Common Issues

  • Invalid Date Format: Ensure the string is in a recognizable date or time format.
  • Ambiguous Date: Be cautious when using month names, as they can vary depending on regional settings.

Integration

DateValue can be used with the DateAdd and DateDiff functions to perform date arithmetic.

Dim dt = DateValue("2/22/2023")
dt = DateAdd("d", 5, dt) 
'Returns: #February 27, 2023#
  • CDate: Converts a string to a Date with more flexibility.
  • Date: Returns the current system date.
  • TimeValue: Converts a string to a Time.