Julie Kurpa
asked on
VBscript does not write Midnight time to log file.
I have a vbscript that tests the status of a service every 30 minutes.
When it executes, it writes a timestamp to a log file and a little message.
I've noticed that the midnight timestamp only writes the date and not the time. See it below. Why is this?
Here's the command:
objTextFile.WriteLine (now)
Here's the output:
3/7/2019 11:30:00 PM
Starting Webpage Status Check
Webpage is available.
-------------------------- ---------- ---------- ---------- ---------- ---------- --------
3/8/2019 <-- notice only the date is written.
Starting Webpage Status Check
Webpage is available.
-------------------------- ---------- ---------- ---------- ---------- ---------- --------
3/8/2019 12:30:00 AM
Starting Webpage Status Check
Webpage is available.
-------------------------- ---------- ---------- ---------- ---------- ---------- --------
When it executes, it writes a timestamp to a log file and a little message.
I've noticed that the midnight timestamp only writes the date and not the time. See it below. Why is this?
Here's the command:
objTextFile.WriteLine (now)
Here's the output:
3/7/2019 11:30:00 PM
Starting Webpage Status Check
Webpage is available.
--------------------------
3/8/2019 <-- notice only the date is written.
Starting Webpage Status Check
Webpage is available.
--------------------------
3/8/2019 12:30:00 AM
Starting Webpage Status Check
Webpage is available.
--------------------------
Without explicit formatting (FormatDateTime(date,forma t)), midnight is stripped. This is the default behavior.
ASKER
Ugh so picky. :)
I googled and changed my code to the following and it writes the date OK. 3/8/2019 10:38:47 AM
Will this work at midnight?
objTextFile.WriteLine FormatDateTime(Now(),vbGen eralDate)
I googled and changed my code to the following and it writes the date OK. 3/8/2019 10:38:47 AM
Will this work at midnight?
objTextFile.WriteLine FormatDateTime(Now(),vbGen
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Ste5an. :)
I'm still not getting it. The example you give prints 1/1/2001 00:00:00 in the log file. How can I get it to print current time even when it is midnight?
I'm trying this code which works but will it work at midnight?
objTextFile.WriteLine FormatDateTime(date, vbShortDate) & " " & FormatDateTime(now(), vbLongTime)
I'm still not getting it. The example you give prints 1/1/2001 00:00:00 in the log file. How can I get it to print current time even when it is midnight?
I'm trying this code which works but will it work at midnight?
objTextFile.WriteLine FormatDateTime(date, vbShortDate) & " " & FormatDateTime(now(), vbLongTime)
By using Now() instead of the date/time literal?! I took it only to show that the above works..
ASKER
I think you are saying that the code is correct. The question mark in your sentence is confusing me.
ASKER
I've confirmed, the following 3 variations all print midnight as 00:00:00 just fine.
objTextFile.WriteLine FormatDateTime(CurrDate, vbShortDate) & " " & FormatDateTime(CurrDate, vbLongTime)
objTextFile.WriteLine FormatDateTime(date, vbShortDate) & " " & FormatDateTime(now(), vbLongTime)
objTextFile.WriteLine (Date & " " & time)
objTextFile.WriteLine "Starting Webpage Status Check "
-------------------------- ---------- ---------- ---------- ---------- ---------- --------
3/10/2019 12:00:00 AM
3/10/2019 12:00:00 AM
3/10/2019 12:00:00 AM
Starting Webpage Status Check
objTextFile.WriteLine FormatDateTime(CurrDate, vbShortDate) & " " & FormatDateTime(CurrDate, vbLongTime)
objTextFile.WriteLine FormatDateTime(date, vbShortDate) & " " & FormatDateTime(now(), vbLongTime)
objTextFile.WriteLine (Date & " " & time)
objTextFile.WriteLine "Starting Webpage Status Check "
--------------------------
3/10/2019 12:00:00 AM
3/10/2019 12:00:00 AM
3/10/2019 12:00:00 AM
Starting Webpage Status Check