Get Current Date

This document provides details and examples for a simple Windows Script Host (WSH) script to retrieve and display the current date.

Script Description

The following VBScript code demonstrates how to access the current system date and format it for display. This script is commonly used for logging, timestamping operations, or providing user-friendly date information.

VBScript Example


' Get the current date object
Dim currentDate
currentDate = Date

' Display the date in a message box
MsgBox "The current date is: " & currentDate, vbInformation, "Current Date"

' You can also display it in the console if running via cscript
' WScript.Echo "The current date is: " & currentDate
            

Explanation

How to Run the Script

  1. Open Notepad or any plain text editor.
  2. Copy and paste the VBScript code above into the editor.
  3. Save the file with a .vbs extension (e.g., GetDate.vbs).
  4. Double-click the saved file to run it. A message box will appear displaying the current date.
  5. Alternatively, open a Command Prompt, navigate to the directory where you saved the file, and type cscript GetDate.vbs to run it in the console.

Output Example

When the script is executed, a message box will appear similar to this:

The current date is: 10/27/2023

(The date shown will be the actual current date when the script is run.)

Note: The format of the date displayed by the Date function is dependent on your system's regional settings.

Further Customization

You can use other VBScript functions to format the date differently, such as:

For more advanced scripting needs, consider exploring PowerShell for Windows environments.