Date and Time Data Literals

This section provides rules on writing date and time literals, characters enclosed in hash signs. VBScript support several formats for the date string like ISO format and US format.

In the previous section, we learned that a date literal is a string representing a date and/or time enclosed in hash signs (#).

Here are some details about how to write a date and/or time literal:

Here is a tutorial example on how to write date and time in different formats:

<html>
<body>
<!-- data_time_literal.html
 - Copyright (c) 2015, HerongYang.com, All Rights Reserved.
-->
<pre>
<script language="vbscript">
   document.writeln("#31-Dec-1999# = " & (#31-Dec-1999#))
   document.writeln("#21:26:00# = " & (#21:26:00#))
'   document.writeln("#21:26:00.123# = " & (#21:26:00.123#))
   document.writeln("#31-Dec-1999 21:26:00# = " _
      & (#31-Dec-1999 21:26:00#))

   document.writeln()
   document.writeln("ISO format:")
   document.writeln("#1999-12-31 21:26:00# = " _
      & (#1999-12-31 21:26:00#))

   document.writeln()
   document.writeln("US format:")
   document.writeln("#12/31/1999 9:26:00 PM# = " _
      & (#12/31/1999 9:26:00 PM#))
</script>
</pre>
</body>
</html>

Here is the output of the sample script:

#31-Dec-1999# = 12/31/1999
#21:26:00# = 9:26:00 PM
#31-Dec-1999 21:26:00# = 12/31/1999 9:26:00 PM

ISO format:
#1999-12-31 21:26:00# = 12/31/1999 9:26:00 PM

US format:
#12/31/1999 9:26:00 PM# = 12/31/1999 9:26:00 PM

Notice that the host environment is using the US format as the default format.

Table of Contents

 About This Book

 Introduction of VBScript - Visual Basic Scripting Edition

Variant Data Type, Subtypes, and Literals

 "Variant" - Data Type and Subtypes

 Data Literals

 Data Literal Examples

 String Data Literals

Date and Time Data Literals

 Arithmetic Operations

 Numeric Comparison Operations and Logical Operations

 String Operations - Concatenation and Comparison

 Variable Declaration and Assignment Statement

 Expression and Order of Operation Precedence

 Statement Syntax and Statement Types

 Array Data Type and Related Statements

 Array References and Array Assignment Statements

 Conditional Statements - "If ... Then" and "Select Case"

 Loop Statements - "For", "While", and "Do"

 "Function" and "Sub" Procedures

 Built-in Functions

 Inspecting Variables Received in Procedures

 Error Handling Flag and the "Err" Object

 Regular Expression Pattern Match and Replacement

 scrrun.dll - Scripting Runtime DLL Library

 Creating Your Own Classes

 IE Web Browser Supporting VBScript

 IIS ASP Server Supporting VBScript

 WSH (Windows Script Host)

 References

 PDF Printing Version