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.
------------------------------------------------------------------------------------
LVL 1
Julie KurpaSr. Systems ProgrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
Without explicit formatting (FormatDateTime(date,format)), midnight is stripped. This is the default behavior.
Julie KurpaSr. Systems ProgrammerAuthor Commented:
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(),vbGeneralDate)
ste5anSenior DeveloperCommented:
No, cause the date in the constant indicates a date focused format, thus midnight is stripped. Thus it's getting a little bit ugly here:

 objTextFile.WriteLine FormatDateTime(#1/1/2001 00:00:00#, vbShortDate) & " " & FormatDateTime(#1/1/2001 00:00:00#, vbShortTime) 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Julie KurpaSr. Systems ProgrammerAuthor Commented:
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)
ste5anSenior DeveloperCommented:
By using Now() instead of the date/time literal?! I took it only to show that the above works..
Julie KurpaSr. Systems ProgrammerAuthor Commented:
I think you are saying that the code is correct.  The question mark in your sentence is confusing me.
Julie KurpaSr. Systems ProgrammerAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.