Page 1 of 1

Date and Time function Help in 3.8 SP1

Posted: Fri Oct 18, 2019 9:35 am
by LBB2019
Hello all, new to the forum so I just want to say thanks in advance for any assistance.

In version 2.5 I used this code to pull and format the Date and Time:

Code: Select all

DateTime = (Format(now, "yymmdd_hhmmss"))
I have just switched to 3.8 SP1 and this function is giving me errors. I searched the forum and have been unsuccessful in finding a solution to the old code. There are other Date functions that do work, but I'd really prefer to have the date and time formatted in that specific manner.

Please help! Thank you!

Re: Date and Time function Help in 3.8 SP1

Posted: Tue Oct 22, 2019 10:16 am
by medupriest
Hello and welcome to the forum. I am not sure if you saw that there is also a 3.8 and newer section of the advanced programming viewforum.php?f=63. I am not sure if there is an answer there, but if the script has changes since we moved to a 64-bit scripting engine, I will make sure we do add an entry.

Re: Date and Time function Help in 3.8 SP1

Posted: Wed Oct 23, 2019 10:05 am
by CrashN8
LBB2019 - Hi there.

You will need to make adjustment to VBScript as mentioned above. Please see details below:

Code: Select all

fromDate = FormatDateTime(Now(),2)
fromTime = FormatDateTime(Now(),3)

MsgBox("Current Date: " + fromDate +Chr(10) + "Current Time: " + fromTime)
This results in MsgBox() as shown here:
date_Time.jpg
You can find details on the VB FormatDateTime() function here - https://www.w3schools.com/asp/func_formatdatetime.asp

Re: Date and Time function Help in 3.8 SP1

Posted: Wed Oct 23, 2019 10:08 am
by vudinwe
Hi, the previous formatting constant "yymmdd_hhmmss" has been deprecated and no longer supported in the new MS VBScript engine.

Below is a sample code that will yield similar output as you expect: 191022_153345

Code: Select all

myDate = FormatDateTime((Now),0)

myYr  = Right("0" & DatePart("yyyy", myDate),2)
myMon = Right("0" & DatePart("m", myDate),2)
myDay = Right("0" & DatePart("d", myDate),2)
myHr  = Right("0" & DatePart("h", myDate),2)
myMin = Right("0" & DatePart("m", myDate),2)
mySec = Right("0" & DatePart("s", myDate),2)

yymmdd_hhmmss = CStr(myYr & myMon & myDay &"_"& myHr & myMin & mySec)
MsgBox yymmdd_hhmmss 
Refer to the references below for explanation of the functions used in the above example:
FormatDateTime()
DatePart()
Right()