O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Now Function

Syntax

Now

Return Value

A Date.

Description

Returns the current date and time based on the system setting.

Example

The following example returns the date 10 days from today:

Dim dFutureDate
dFutureDate = DateAdd("d", 10, Now)

Programming Tips and Gotchas

  • It’s often overlooked that workstations in a modern Windows environment are at the mercy of the user! If your application relies on an accurate date and time setting, you should consider including a line in the workstation’s logon script to synchronize the time with one of the servers. Many so-called bugs have been traced to a workstation that has had its date or time wrongly altered by the user. The following line of code, when added to the logon script of an NT/Windows 2000 machine, synchronizes the machine’s clock with that of a server called NTSERV1:

    net time \\NTSERV1 /set
  • If you convert the date returned by Now to a string, it takes the Windows General Date format based on the locale settings of the local computer. The U.S. setting for General Date is mm/dd/yy hh:mm:ss.

  • The Now function is often used to generate timestamps. However, for short-term timing and intra-day timestamps, the Timer function, which returns the number of milliseconds elapsed since midnight, affords greater precision.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required