1 + 1 = ?

Both VBScript and JScript include good math and arithmetic support, by using the inbuilt functions you can easily work with numbers, dates and times (see the Arithmetic and Date & Time sections of the VBScript reference for a list of functions).

Now let's try another example to calculate your age in seconds using the inbuilt DateDiff() function.

Option Explicit

'Define the variables
Dim Birthday, AgeInSeconds

'Get the users DOB
Birthday = InputBox("Please enter your date of birth:")

'Calculate the difference using DateDiff
AgeInSeconds = DateDiff("s", Birthday, Now)

'Display the results
WScript.echo "You are " & AgeInSeconds & " seconds old."

When you run this script, it's first going to ask your date of birth, enter it and click OK to continue.

InputBox Example

After doing some internal calculations using the DateDiff() function the WScript.Echo method is used to display the difference between the date entered (your DOB) and the current time (retrieved using the Now() function).

Popup Example

This script introduced a few new functions and features. On the first line you'll notice the statement "Option Explicit" this is used to tell the script interpreter that all variables must be defined before use, it's optional but it will save you in the future from misspelled variable bugs. The DateDiff function is one of the many inbuilt functions for dealing with date and time, it's parameters can be found on its reference page. The Now function was used to get the current system time, this is another inbuilt function and comes in very handy when dealing with dates and times.

< Interacting with Users

Summary >

PC Tools, the PC Tools logo and Spyware Doctor are either trademarks or registered trademarks of PC Tools Technology Pty Ltd. Microsoft, Windows, Windows Vista, the Windows logo and / or other Microsoft products referenced are either registered trademarks or trademarks of Microsoft Corporation in the United States and / or other countries.