Boontawee Home
Boontawee Home

Reputation: 1053

VBS Msgbox(DateTime.Now.ToString("yyyyMMdd HH:mm:ss")) show error

Please help. My code just simple but show error as in the picture.

Msgbox DateTime.Now.ToString("yyyyMMdd HH:mm:ss")

enter image description here

Upvotes: 0

Views: 1670

Answers (1)

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38745

There is no DateTime object in VBScript, just plain Date variables and functions:

>> d = Date()
>> n = Now()
>> WScript.Echo TypeName(d), d, TypeName(n), n
>> WScript.Echo TypeName(Month(n)), Month(n)
>> s = FormatDateTime(n)
>> WScript.Echo TypeName(s), s
>>
Date 21.06.2017 Date 21.06.2017 05:58:13
Integer 6
String 21.06.2017 05:58:13

You can use a .NET System.Text.StringBuilder to do more fancy formatting. (cf here)

Upvotes: 1

Related Questions