Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format a datetime with minimal separators and timezone in VBScript?

I have the following code in C#:

DateTime dt = GetDateTime();
string formatted = dt.ToString("yyyyMMddTHHmmsszz");

which returns a date in the following format:

20100806T112917+01

I would like to be able to get the same results in VBScript (for a legacy ASP application). It is especially important that I get the UTC offset information, or have the time converted to UTC.

How do I do that?

like image 251
Damian Powell Avatar asked Dec 28 '22 09:12

Damian Powell


1 Answers

For date formatting, I like using the .NET StringBuilder class from VBScript:

Option Explicit

Dim sb : Set sb = CreateObject("System.Text.StringBuilder")
sb.AppendFormat "{0:yyyyMMddTHHmmsszz}", Now()
Response.Write sb.ToString()

The above returns:

20100806T201139-07

This assumes that you have .NET installed on your web server.

like image 168
Cheran Shunmugavel Avatar answered Jan 13 '23 15:01

Cheran Shunmugavel