Capt. Horatio T.P. Webb
SEQUENTIALS
VbScript and Javascript

Parks -- Spring 2003
Last Updated 12 PM 6/11/2015

 Strings    Mathematics    Math Functions and Methods    Arrays    Date and Time

 
 Strings
 
VBScript FunctionsJavascript Properties and Methods
 ASC

  usage is:

  data_name=ASC("some character")

  Returns the ascii code number of the character
  (i.e., where the character appears on the list of ASCII characters)

  e.g., ASC("A") returns the integer 65.
  (this is reverse of CHR)

 charCodeAt() method

  usage is:

  data_name=some_string.charCodeAt(integer)

Returns the ASCII character number of the character at the location in the string specified by the integer. The characters in the string are numbered beginning at 0.

  e.g., "TEXAS".charCodeAt(3) returns the ASCII character number of the fourth character ("A") which is 65.

 CHR

  usage is:

  data_name=CHR(some integer <= 255)


  Returns the character of the ASCII code number

  e.g., fred=CHR(65) returns the character A
  (this is the reverse of ASC)

 fromCharCode() method

  usage is:

  data_name=String.fromCharCode(integer,integer,integer,...)

Returns the ascii characters associated with a list of one or more comma separated integers. (i.e., the integers are between 0 and 255 that define the integer location of where the character appears on the list of ASCII characters)

  e.g., String.fromCharCode(65) returns the character "A".

  e.g., String.fromCharCode(65,66,67) returns the character string "ABC".
Note that you use the String object here -- not the name of user defined string.

  Ucase

  usage is:

  Ucase("string")

  Converts all the string characters to upper case

  e.g., fred=ucase("to be or not to be")
  returns "TO BE OR NOT TO BE"

  toUpperCase method

  usage is:

  some_string.toUpperCase();

Converts all the string characters to upper case.
No parameters are used -- but the parenthesis must be used.

  e.g.,

fred="to be or not to be";
new_fred=fred.toUpperCase();

  assigns "TO BE OR NOT TO BE" to new_fred

  Lcase

  usage is:

  Lcase("string")

  returns the string with all characters converted to lower case

  e.g., fred=Lcase("Internet")
  returns "internet"

  toLowerCase method

  usage is:

  some_string.toLowerCase();

Converts all the string characters to lower case.
No parameters are used -- but the parenthesis must be used.

  e.g.,

fred="Internet";
new_fred=fred.toLowerCase();

  assigns "internet" to new_fred

  Ltrim

  usage is:

  Ltrim("string")

  removes leading blanks (left side) from the string

  e.g., fred=Ltrim(" 123")
  returns "123"

  Rtrim

  usage is:

  Rtrim("string")

  removes trailing (right side) blanks from the string

  e.g., fred=Rtrim("   123   ")
  returns "   123"

  Trim

  usage is:

  Trim("string")

  removes both leading and trailing blanks from the string

  e.g., fred=Trim("  123  ")
  returns "123"

  Left

  usage is:

  Left("string",number_of_characters_to_remove)

  remove the left-most number of characters specified

  e.g., fred=Left("123456789",5)
  returns "12345"

  Right

  usage is:

  Right("string",number_of_characters_to_remove)

  remove the right-most number of characters specified

  e.g., fred=Right("123456789",5)
  returns "56789"

  StrReverse

  usage is:

  new_string = StrReverse( original_string )

StrReverse reverses the sequence of characters in original_string and returns the new string to new_string.

  e.g.,
  fred = StrReverse("123456new890")
  fred gets assigned the value "098wen654321"

  concat (string version, see array version here)

  usage is:

some_string.concat( string-1, string-2, string-3, ... )

the .concat (string version) attaches to the END of some_string the string values of string-1, string-2, string-3,...etc.

  e.g.,
  fred="ABC";
  fred.concat("DEF","GHI","J","K");
  fred's new value is "ABCDEFGHIJK"

  slice (string version, see array version here)

  usage is:

some_string.slice( begin , end );

the .slice (string version) extracts characters from some_string strating at the index value of begin and continues up to BUT NOT including the index value end. If the end is specified as a negative number, the process stops at this value from the end of the some_string

(i.e.,

if end = -1, the last character is NOT copied to some_string;
if end = -2, the last two characters are NOT copied to some_string;
if end = -3, the last three characters are NOT copied to some_string;

if end is not specified, all elements from begin to the end of some_string are copied. The original contents of some_string are not modified or destroyed.

  e.g.,

  fred = "ABCDEFGH";
  alice = fred.slice(2,5);
  alice gets the value "CDE"

  fred = "ABCDEFGH";
  alice = fred.slice(2,-2);
  alice gets the value "CDEF"

  fred = "ABCDEFGH";
  alice = fred.slice(2);
  alice gets the value "CDEFGH"

  InStr

  usage is:

  InStr(start_char,"string-1","string-2",case_match)

Beginning at start_char, the function finds the location of string-2 in string-1. The function returns the location (character number) where string-2 begins. start_char is optional. string-1 and string-2 are BOTH required, case_match is optional -- a 0 means case sensitive (exact matches only) and a 1 means case insensitive (exact matches only). Returns a zero is string-2 is NOT found in string-1.

  e.g.,
     fred= InStr(3,"123456new890","new",0)
     fred= InStr("123456new890","new",0)
     fred= InStr("123456new890","new")
  all return a 7

  InStrRev(start_char,"string-1","string-2",case_match)

works the same as InStr except that the search is performed FROM THE END of the string TO the beginning. start_char is optional -- if omitted the search starts at the LAST character.

  indexOf() method
  lastIndexOf() method
  search() method
  match() method


  indexOf usage is:

  some_string.indexOf(search_string ,start_char)

Beginning at start_char, the method finds the location of search_string in some_string. The method returns the location (character number) where search_string begins. start_char is optional. if the search_string is not found the method returns a -1. if the start_char is omitted, the method begins at string location zero (i.e., the first character). This method returns the location of the first occurrence of the search_string (i.e., the search is from left to right)

  e.g.,
     fred="123456new890new";
     new_is_at= fred.indexOf("new")
  new_is_at has the value 6.


  lastIndexOf usage is:

  some_string.lastIndexOf(search_string ,start_char)

Beginning at start_char, the method finds the location of search_string in some_string. The method returns the location (character number) where search_string begins. start_char is optional. if the search_string is not found the method returns a -1. if the start_char is omitted, the method begins at the last string location. This method returns the location of the last occurrence of the search_string (i.e., the search is from right to left)

  e.g.,
     fred="123456new890new";
     new_is_at= fred.lastIndexOf("new")
  new_is_at has the value 12.


  search usage is:

some_string.search(string);

The location where string appears in some_string is returned. If the string is not found a -1 is returned.

e.g.,

fred="12xx12341234";
xx_location=fred.search("xx");

assigns 2 to xx_location.


  match usage is:

some_string.match(string);

Creates an array where each occurrence of the string that appears in some_string is stored. Note that all the values in the array are the same.

e.g.,

fred="123412341234";
array_of_12=fred.match("12");

assigns "12" to array_of_12[0], "12" to array_of_12[1],and "12" to array_of_12[2]

  Len

  usage is:

  Len("string")

  returns the length of the string

  e.g., fred=len("12345678")
  returns 8

  .length property (string version -- see array version here)

  usage is:

  some_string..length

  returns the length of the string

  e.g., fred="12345678";

  e.g., length_of_fred=fred.length;
  assigns length_of_fred the value 8

  Mid

  usage is:

  Mid("string",start_char,number_of_characters_to_retreive)

  beginning at start_char,
  the function retrieves number_of_characters_to_retreive
  from the string

  e.g., fred=Mid("123456789",6,3)
  returns "678"

 charAt() method
 substr() method
 substring() method


  charAt() usage is:

  data_name=some_string.charAt(integer)

Returns the character at the location in the string specified by the integer. The characters in the string are numbered beginning at 0.

  e.g., some_string.charAt(3) returns the fourth character in the string.


  substring() usage is:

  new_string=some_string.substring(start_char,end_char);

Returns the string at the location in the string starting at start_char and up to BUT NOT INCLUDING end_char. The characters in the string are numbered beginning at 0 (e.g.,

fred="Yellow Rose of Texas";
new_string=fred.substring(5,6);

assigns "w" to new_string.


  substr() usage is:

  new_string=some_string.substr(start_char,number_of_characters_to_extract);

Returns the string at the location in the string starting at start_char and then extracting a number of characters equal to number_of_characters_to_extract. The characters in the string are numbered beginning at 0. If the second parameter is omitted, all the characters in the string to the right of the start_char are returned. (e.g.,

fred="Yellow Rose of Texas";
new_string=fred.substr(5,6);

assigns "w Rose" to new_string.

  replace

  usage is:

  replace ( string, search_for_string, replace_with_string, start_char, number_of_replacements, comparison_type)

Beginning at start_char, the function finds the search_for_string in string and replaces it with replace_with_string. The value of number_of_replacements determines how many times this can occur. The default value for start_char if omitted is 1.
(If start_char is greater than one, then the beginning characters from 1 to start_char-1 are NOT returned)
The default value for number_of_replacements if omitted is -1 (-1 means replace all).
The value of comparison_type is either 0 (binary) or 1 (text).

The replace function can return:

  • a zero length string if the length of string is zero.
  • an error if the string is NULL
  • the original string less all occurrences of the search_for_string removed if the replace_with_string is of length zero
  • a zero length string if start_char is greater than the length of string
  • the original string if replace_with_string = 0

  e.g., fred=replace("123412341234","23","xx",5,1,1)
  returns "1xx41234"
(Note in this example, since start-char is greater than 1 (i.e., it is 5), the function begins returning characters at position 5)

replace method

  replace usage is:

some_string.replace(string-1, string-2);

The value of string-1 is replaced in some_string with the value of string-2 once. Only the first occurrence in the string from left to right is replaced.

e.g.,

fred="123412341234";
new_fred=fred.replace("23","xx")
assigns "1xx412341234" to new_fred

This javascript replace method ONLY replaces the first occurrence of string-1 with string-2. To replace all occurrences we need to use a loop like this:

while ( some_string.indexOf(string-1) > -1)
   some_string.replace(string-1, string-2);

This while loop:

  1. asks if string-1 is in some_string. If it is (indicated by the indexOf method returning an integer location) then the .replace method substitutes string-2 for string-1.
  2. the while loop continues to perform the replacements until no more occurrences of string-1 are found (indicated by the .indexOf method returning a -1).
  Space

  usage is:

  Space(number_of_spaces)

  creates a string with number_of_spaces spaces.

  e.g., fred=Space(4)
  returns "    "

  FormatNumber

  usage is:

  FormatNumber( expression or variable , number_of_digits_to_the_right_of_the_decimal, include_leading_zero, use_parenthesis_for_negatives, group_digits)

  converts a numeric expression or numeric variable to a string.
  the expression or variable name is required.
  the last four parameters are optional
  they default to Regional Settings
  (see your Regional Settings by clicking "Start, Control Panel, then Regional Settings")

  1. number_of_digits_to_the_right_of_the_decimal non-negative integer (if zero there is no decimal printed)

    the last three parameters use zero for false, -1 for true, or -2 to use the current Regional Settings

  2. include_leading_zero if a fraction (0 for false, -1 for true, -2 to use the current Regional Settings)
  3. use_parenthesis_for_negatives(0 for false, -1 for true, -2 to use the current Regional Settings)
  4. group_digits -- (i.e., use commas to separate the groups of digits) (0 for false, -1 for true, -2 to use the current Regional Settings)

  e.g., formatnumber(17869.435)
  returns "17,869.43"

Formatting numbers

There are two javascript formatting methods:

  1. .toFixed(n)

    some_floating point number.toFixed (n) -- where n is the nunumber of digits to the right of the decimal.

    this_floating point number = 174.3398; new number=this_floating point number.toFixed(2);

    So, new number = 174.34 -- Note that the method rounds.

    this_floating point number = 4.3; new number=this_floating point number.toFixed(5);

    So, new number = 4.3000. Note that the method adds zeroes to the end.

  2. .toPrecision(n)

    some_floating point number.toPrecision (n) -- where n is the Total number of digits beginning at the left-most digit of the number (not the decimal point)

    this_floating point number = 174.3398; new number=this_floating point number.toPrecision(4);

    So, new number = 174.3 -- Note that the method removes digits.

    this_floating point number = 43.3; new number=this_floating point number.toPrecision(5);

    So, new number = 43.300. Note that the method adds zeroes to the end.

  FormatCurrency

  usage is:

  FormatCurrency( expression or variable , number_of_digits_to_the_right_of_the_decimal, include_leading_zero, use_parenthesis_for_negatives, group_digits)

  converts a numeric expression or numeric variable to a string.

  after conversion the currency symbol ($) is added to the left of the string
  the expression or variable name is required.
  the last four parameters are optional
  they default to Regional Settings
  (see your Regional Settings by clicking "Start, Control Panel, then Regional Settings")

  1. number_of_digits_to_the_right_of_the_decimal non-negative integer (if zero there is no decimal printed)

    the last three parameters use zero for false, -1 for true, or -2 to use the current Regional Settings

  2. include_leading_zero if a fraction (0 for false, -1 for true, -2 to use the current Regional Settings)
  3. use_parenthesis_for_negatives(0 for false, -1 for true, -2 to use the current Regional Settings)
  4. group_digits -- (e.g., use commas to separate the groups of digits) (0 for false, -1 for true, -2 to use the current Regional Settings)

  e.g., formatcurrency(17869.435)
  returns "$17,869.43"

  FormatPercent

  usage is:

  FormatPercent( expression or variable , number_of_digits_to_the_right_of_the_decimal, include_leading_zero, use_parenthesis_for_negatives, group_digits)

  converts a numeric expression or numeric variable to a string.

  the numeric result is multiplied by 100 before conversion and the percent symbol (%) added to the right
  the expression or variable name is required.
  the last four parameters are optional
  they default to Regional Settings
  (see your Regional Settings by clicking "Start, Control Panel, then Regional Settings")

  1. number_of_digits_to_the_right_of_the_decimal non-negative integer (if zero there is no decimal printed)

    the last three parameters use zero for false, -1 for true, or -2 to use the current Regional Settings

  2. include_leading_zero if a fraction (0 for false, -1 for true, -2 to use the current Regional Settings)
  3. use_parenthesis_for_negatives(0 for false, -1 for true, -2 to use the current Regional Settings)
  4. group_digits -- (i.e., use commas to separate the groups of digits) (0 for false, -1 for true, -2 to use the current Regional Settings)

  e.g., formatpercent(17.435)
  returns "1,743.50"

  FormatDate

  usage is:

  FormatDate( date string , format number)


   0 Display a date and/or time. If there is a date part, display it as a short date. If there is a time part, display it as a long time. If present, both parts are displayed.
  1 Display a date using the long date format specified in your computer's regional settings.
  2 Display a date using the short date format specified in your computer's regional settings.
  3 Display a time using the time format specified in your computer's regional settings.
  4 Display a time using the 24-hour format (hh:mm).

  e.g.,
  x="12/15/1998 14:24:59"
  formatdatetime(x,2)
  returns "12/15/1998"
  formatdatetime(x,3)
  returns "2:24:59PM"

  String

  usage is:

  String(number_of_occurences,"character",)

  creates a string with number_of_occurences copies of the character

  e.g., fred=String (5,"a")
  returns "aaaaa"

  Hex

  usage is:

  Hex(integer)

  returns the hexadecimal (base 16) equivalent of the integer

  e.g., fred=Hex(15321)
  returns 3BD9

  Oct

  usage is:

  Oct(integer)

  returns the octal (base 8) equivalent of the integer

  e.g., fred=Oct(15321)
  returns 35731

Split

usage is:

Dim array name =
Split ( string, "character(s) used to define the split positions",
count, compare )

The function searches string and retrieves substrings that appear BETWEEN occurrences of the "character(s) used to define the split positions" and returns them to a zero-based array that appears on the left of the = sign.
"character(s) used to define the split positions" is optional -- if not provide a space is the assumed delimiter. The "character(s) used to define the split positions" is(are) NOT stored in the array.
count is optional -- if -1 or omitted ALL substrings are returned. compare is optional -- 0 if text, 1 if binary.

e.g.,

fred="1234,5678,abcd";
dim fred_array=Split(fred,",")

assigns "1234" to fred_array(0), "5678" to fred_array(1) and "abcd" to fred_array(2).

split method

  usage is:

some_string.split(character_to_use_as_define_the_split;

The characters in some_string are split into multiple strings and stored in an array. The character in the parenthesis (character_to_use_to_define_the_split) determines where the split occurs. This character is not stored in the array.

e.g.,

var fred="1234,5678,abcd";
var fred_array=fred.split(",");

assigns:
"1234" to fred_array[0],
"5678" to fred_array[1], and
"abcd" to fred_array[2].

String Conversions

Seven conversions to strings are provided:

  1. CBool(expression) converts the expression to a Boolean true or false. If the expression is equal to 0 it returns false otherwise it returns true.
  2. CByte(expression) converts the expression to a byte (i.e., a integer between 0 and 255). If the expression is not in this range a run-time error occurs.+
  3. CCur(expression) converts the expression to a currency value based on "Regional Settings"
  4. CDbl(expression) converts the expression to a double precision floating point number with 15 significant digits.
  5. CInt(expression) converts the expression to a 2 byte integer. The value of expression must be between -32,768 and +32,767.
  6. CLng(expression) converts the expression to a 4 byte integer.The value of expression must be between -2,147,483,648 and +2,147,483,647.
  7. CSng(expression) converts the expression to a single precision floating point number with 7 significant digits.
  8. CStr(expression) converts the expression to a string.
parseInt() function
parseFloat() function
toString()

These functions convert strings to numbers.

parseInt usage is:

fred=parseInt(string containing a number);

returns a integer.

parseFloat usage is:

fred=parseFloat(string containing a number);

returns a number of digits, a decimal point and a minus sign if present. The function ignores non-numerics.

Note: these are NOT methods -- they are functions. You do not use object notation here like you do on must methods in this column. You might suppose you should say:

variable_name.parseInt();

WRONG. This would imply that parseInt() was a method. It is NOT. It is a function that you pass an argument like this:

variable_2 = parseInt(variable_1);

It is always possible that javascript will be unable to convert that value you specify to an integer. For example this:

alice="abcd";
fred=parseInt(alice);

This will results in fred getting the value "NAN" (i.e., Not A Number). To prevent this you can check first:

if ( isNaN(alice) )
        alert ("alice is not a number, it is:"+alice);
else
    {
        fred=parseInt(alice);
        alert ("alice converted OK, fred="+fred);
    }

NOTE: The full format of parseInt is:

some_variable=parseInt(some_string,radix)

The radix term defines the base of the number to be returned. Normally this defaults to base 10. However, you should supply the base for the number you wish to return because there are a few places where unintended results occur. Most often this happens with the strings "08" and "09". Both parseInt("08") and parseInt("09") return zero!. The javascript convention for numeric constants is:

"0x" followed by some digits is assumed to be hexadecimal (base 16)(e.g., 0xff is 255)
"0" followed by some digits is assumed to be octal (base 8)(e.g., 044 is 36)

Thus javascript checks the beginning of the string to determine the base (radix). If it encounters a "0x" as the first two characters it assumes this is a hexadecimal string; if it encounters a zero as the first character it assumes it is an octal; otherwise it assumes it is decimal. Thus "08" and "09" convert to zero since the strings have invalid octal values (i.e., 8 and 9). But "00", "01", "02", "03", "04", "05", "06", and "07" are correctly converted from octal to 0, 1, 2, 3, 4, 5, 6, and 7.

Just to be sure always specify the radix.

toString()

the .toString method converts a number to a string. Usage is:

variable containing a number.toString();

For example:

fred=14;
alice = fred.toString();

Returns "14" to alice.

fred=-14.33;
alice = fred.toString();

Returns "-14.33" to alice.

You can also change the numeric base (or radix) by using:

variable containing a number.toString(radix);

For example:

fred=17;
alice = fred.toString(2);

Returns "10001" to alice (one 16s + no 8s + no 4s + no 2s + 1 unit = 17).

fred=17;
alice = fred.toString(3);

Returns "122" to alice (1 9s + 2 3s + 2 units = 17).

fred=17;
alice = fred.toString(4);

Returns "101" to alice (1 16s + 0 4s + 1 unit = 17).

fred=17;
alice = fred.toString(8);

Returns "21" to alice (2 8s+ 1 unit = 17).

fred=17;
alice = fred.toString(13);

Returns "11" to alice (1 16s + 1 unit).

 
  Mathematical Operations 
 
VBScriptJavascript
  Addition

  usage is:

  (numeric variable or constant+ (numeric variable or constant)

  sums the two values

  e.g., fred=14 + 21
  returns 35

  e.g., fred=alice + 21
  returns current value of alice + 21

Same as VBScript but adds:

variable++

increments the value of by 1.

variable += constant or expression

adds the value of the constant or expression to the value variable

  Subtraction

  usage is:

  (numeric variable or constant- (numeric variable or constant)

  calculate the difference between the two values

  e.g., fred=14 - 2
  returns 12

  e.g., fred=alice - 21
  returns current value of alice - 21

Same as VBScript but adds:

variable--

decrements the value of by 1.

variable -= constant or expression

subtracts the value of the constant or expression from the value variable /

  Multiplication

  usage is:

  (numeric variable or constant* (numeric variable or constant)

  multiplies the two values

  e.g., fred=14 * 2
  returns 28

  e.g., fred=alice * 2
  returns current value of alice * 2

same as VBScript
  Division (floating point)

  usage is:

  (numeric variable or constant/ (numeric variable or constant)

  divides first value by the second value

  e.g., fred=14 / 2
  returns 7

  e.g., fred=alice / 2
  returns current value of alice divided by 2

same as VBScript
  Division (integer)

  usage is:

  (numeric variable or constant\ (numeric variable or constant)

  divides first value by the second, but stores only the integer portion of the answer

  e.g., fred=14 \ 6
  returns 2

  e.g., fred=36 \ 5
  returns 7

  Exponentiation

  usage is:

  (numeric variable or constant^ (numeric variable or constant)

  raises first value to the power of the second value

  e.g., fred=4 ^ 3
  returns 64

  e.g., fred=3 ^ 2
  returns 9

pow() method

Raises a number to a power. Two arguments must be supplied to the method.

usage is:

fred=Math.pow(number,power);

  e.g., fred=math.pow(4,3);
  returns 64 to fred

  e.g., fred=Math.pow(3,2);
  returns 9 to fred.

  Modular Arithmetic (mod)

  usage is:

  (numeric variable or constantmod (numeric variable or constant)

  divides the first value by the second and returns the remainder

  e.g., fred=4 mod 3
  returns 1

  e.g., fred=3 mod 3
  returns 0

  Modular Arithmetic %

  usage is:

  (numeric variable or constant% (numeric variable or constant)

  divides the first value by the second and returns the remainder

  e.g., fred=4 % 3;
  assigns 1 to fred

  e.g., fred=3 % 3;
  assigns 0 to fred

  Negation (unary minus)

  usage is:

  -(numeric variable or constant)

  multiplies the value by -1

  e.g., fred= - 3
  returns -3

  e.g., fred= - alice
  returns -1 * alice

same as VBSscript
  Operator Precedent

  The math operators are executed in the following order of precedent:

  1. From the inner-most parenthesis to the outermost parenthesis
  2. Exponents (^)
  3. Negation (-)
  4. Multiplication (*) and Division (/ or \) from left to right
  5. Modulo arithmetic (mod)
  6. Addition (+) and Subtraction (-/) from left to right
  7. String concatenation (+ or &)

  Operator Precedent

  The math operators are executed in the following order of precedent:

  1. From the inner-most parenthesis to the outermost parenthesis
  2. Negation (-)
  3. Multiplication (*) and Division (/ or \) from left to right
  4. Addition (+) and Subtraction (-/) from left to right
  5. String concatenation (+ or &)

 
   Mathematical Functions (vbscript) and Mathematical Methods (javascript) 
 
VBScript FunctionsJavascript Properties and Methods
  Absolute Value (ABS)

  usage is:

  ABS(numeric variable or constant)

  returns the value as a positive number

  e.g., fred= ABS (-3)
  returns 3

  e.g., fred= ABS (alice)
  returns alice as a positive number

abs() method

usage is:

Math.abs(constant, variable or expression);

returns the value of the constant, variable or expression as a positive number.

  e.g., fred= Math.abs(-3);
  assigns 3 to fred

  e.g., fred= Math.abs(alice);
  assigns alice to fred as a positive number

  Sign (SGN)

  usage is:

  SGN(numeric variable or constant)

  returns the value the sign
  if the value is > 0 the function returns a 1
  if the value is = 0 the function returns a 0
  if the value is < 0 the function returns a -1

  e.g., fred= SGN (-3)
  returns -1

  e.g., fred= SGN (+3)
  returns 1

  e.g., fred= SGN (0)
  returns 0

  Logarithm -- natural (LOG)

  usage is:

  LOG(numeric variable or constant)

  returns the natural logarithm of the value (i.e., base e or 2.718282)

  e.g., fred= LOG (10)
  returns 2.3025
  (i.e., 2.718282 ^ 2.3025 = 10 )
  To find logarithms of a number (e.g., x) for another base (e.g., b) use the relationship:
  logarithm base b of the number x = log(x) / log(b)

  e.g., logarithm of 100 base 10 = log(100)/log(10)=2

log() method

  usage is:

  Math.log(numeric variable or constant);

  returns the natural logarithm of the value (i.e., base e or 2.718282)

  e.g., fred= Math.log(10)
  returns 2.3025
  (i.e., 2.718282 raised to the power 2.3025 = 10 )
  To find logarithms of a number (e.g., x) for another base (e.g., b) use the relationship:
  logarithm base b of the number x = log(x) / log(b)

  e.g., logarithm of 100 base 10 = log(100)/log(10)=2

  Exponentiation (EXP)

  usage is:

  EXP(numeric variable or constant)

  returns the e raised to the power of the value

  e.g., fred= EXP (2)
  returns 7.3890 (i.e., 2.718282 ^2)

  exp() method

  usage is:

  Math.exp(numeric variable or constant)

  returns the e raised to the power of the value

  e.g., fred= Math.exp(2)
  returns 7.3890 (i.e., 2.718282 raised to the power 2)

  Square Root(SQR)

  usage is:

  SQR(numeric variable or constant)

  returns the square root of the value

  e.g., fred= SRQ (16)
  returns 4

  sqrt() method

  usage is:

  Math.sqrt(numeric variable or constant)

  returns the square root of the value

  e.g., fred= Math.sqrt(16);
  returns 4

  Sin (SIN)

  usage is:

  SIN(numeric variable or constant)

  returns the trigonometric sin of the value

  the function value must be expressed in radians NOT in degrees

  to get from degrees to radians use the expression:

  radians = degrees*3.14159/180.

  to go from radians to degrees use the expression:

  degrees = radians*180.0/3.14159

  e.g., fred= SIN (45.0*3.14159/180.0)
  returns 0.707106

  sin() method

  usage is:

  Math.sin(numeric variable or constant)

  returns the trigonometric sin of the value

  the function value must be expressed in radians NOT in degrees

  to get from degrees to radians use the expression:

  radians = degrees*3.14159/180.

  to go from radians to degrees use the expression:

  degrees = radians*180.0/3.14159

  e.g., fred= Math.sin(45.0*3.14159/180.0);
  returns 0.707106

  Cosine (COS)

  usage is:

  COS(numeric variable or constant)

  returns the trigonometric cosine of the value

  the function value must be expressed in radians NOT in degrees

  to get from degrees to radians use the expression:

  radians = degrees*3.14159/180.

  to go from radians to degrees use the expression:

  degrees = radians*180.0/3.14159

  e.g., fred= COS (45.0*3.14159/180.0);
  returns 0.707106

  cos() method

  usage is:

  Math.cos(numeric variable or constant)

  returns the trigonometric cosine of the value

  the function value must be expressed in radians NOT in degrees

  to get from degrees to radians use the expression:

  radians = degrees*3.14159/180.

  to go from radians to degrees use the expression:

  degrees = radians*180.0/3.14159

  e.g., fred= Math.cos(45.0*3.14159/180.0);
  returns 0.707106

  Tangent (TAN)

  usage is:

  TAN(numeric variable or constant)

  returns the trigonometric tangent of the value

  the function value must be expressed in radians NOT in degrees

  to get from degrees to radians use the expression:

  radians = degrees*3.14159/180.

  to go from radians to degrees use the expression:

  degrees = radians*180.0/3.14159

  e.g., fred= TAN (45.0*3.14159/180.0);
  returns 1.0

  tan() method

  usage is:

  Math.tan(numeric variable or constant)

  returns the trigonometric tangent of the value

  the function value must be expressed in radians NOT in degrees

  to get from degrees to radians use the expression:

  radians = degrees*3.14159/180.

  to go from radians to degrees use the expression:

  degrees = radians*180.0/3.14159

  e.g., fred= Math.tan(45.0*3.14159/180.0);
  returns 1.0

  ArcTangent (ATN)

  usage is:

  COS(numeric variable or constant)

  returns the trigonometric arctangent of the value (i.e., the angle whose tangent is the value)

  the function value must be expressed in radians NOT in degrees

  to get from degrees to radians use the expression:

  radians = degrees*3.14159/180.

  to go from radians to degrees use the expression:

  degrees = radians*180.0/3.14159

  e.g., fred= ATN (1.0*180.0/31.14159)
  returns 45.0

  atan() method

  usage is:

  atan(numeric variable or constant)

  returns the trigonometric arctangent of the value (i.e., the angle whose tangent is the value)

  the function value must be expressed in radians NOT in degrees

  to get from degrees to radians use the expression:

  radians = degrees*3.14159/180.

  to go from radians to degrees use the expression:

  degrees = radians*180.0/3.14159

  e.g., fred= Math.atan (1.0*180.0/31.14159)
  returns 45.0

  Fix (FIX) and Int (INT)

  usage is:

  FIX(numeric variable or constant)

  INT(numeric variable or constant)

  both functions return the integer portion of the value

  e.g., fred= FIX (45.3)
  returns 45

  e.g., fred= INT (45.3)
  returns 45
  These function are the same for positive numbers, but different for negative numbers.
  The FIX function rounds to the next higher integer, and INT to the next lower integer.

  e.g., fred= FIX (-5.3)
  returns -5

  e.g., fred= INT (-5.7)
  returns -6
  NOTE: the function Cint always rounds -- it doesn't truncate

ceil() method
floor() method
round() method


ceil() usage is:

fred=Math.ceil(floating point number);

This method rounds up to the next larger integer.


floor() usage is:

fred=Math.floor(floating point number);

This method rounds down to the next smaller integer.


round() usage is:

fred=Math.round(floating point number);

This method rounds to the nearest integer (if < 0.5 it rounds down -- if > 0.5 it rounds up)

  min and max

  min usage is:

some_variable = Math.min ( arg-1 , arg-2, arg-3, ...);

returns to some_variable the smaller of the numbers arg-1, arg-2, arg-3, etc.

  e.g.,

r=Math.min(3,5,7,1,0,-1);

returns -1 to r.

  max usage is:

some_variable = Math.max ( arg-1 , arg-2, arg-3, ...);

returns to some_variable the largest of the numbers arg-1, arg-2, arg-3, etc.

  e.g.,

r=Math.max(3,5,7,1,0,-1);

returns 7 to r.

There is no specific built-in min and max function in javascript for finding the largest and smallest elements in an array. There are many work-around for this issue (see this discussion). As noted in the discussion the fastest way to do this is to:

  1. set the min or max to first array element
  2. then iterate through the remaining array elements, testing each elements

For minimums the code for finding the smallest value in array named fred would be:

minfred = fred[0];
for (i=1; i < fred.length; i++)
    if (fred[i] < minfred) minfred = fred[i];

For a maximum:

maxfred = fred[0];
for (i=1; i < fred.length; i++)
    if (fred[i] > maxfred) maxfred = fred[i];

To find both the minimum and maximum:

minfred = fred[0];
maxfred = fred[0];
for (i=1; i < fred.length; i++)
    {
        if (fred[i] > maxfred) maxfred = fred[i];
        if (fred[i] < minfred) minfred = fred[i];
    }

(see Cyberknight's answer (Apr 2 2014) in the stackoverflow.com discussion link above)

  Random Numbers (RND)

  usage is:

  RND

  returns a number between 0 and 1 (i.e., 0.0 > RND < 1.0)

  note that the result is never 0.0 or 1.0

  e.g., fred=RND
  returns 0.3103476
  You can generate random numbers in other ranges.
  To generate numbers between a and b use:
  fred=a+(b-a)*RND

  e.g., to generate numbers between 1.0 and 27.0, use:
  fred=1.0+(26.0)*RND
  Note that the number 27.0 will never occur since RND will never generate a 1.0

random method

usage is:

fred=Math.random();

Returns a pseudo-random number between 0.0 and 1.0.

  Randomize

  usage is:

  Randomize

  causes a new sequence of random numbers to be generated
  note that if you do not use randomize the program will always generate
  the same sequence of random numbers.
  By using randomize a new sequence is generated each time.

 
 
  Array Operations 
 
VBScript FunctionsJavascript Properties and Methods
UBound and LBound

usage is:

variable = UBound ( array_name , dimension )

and

variable = LBound ( array_name , dimension )

UBound returns to variable the largest subscript available in the array named array_name. This is NOT the number of array elements (note most often arrays begin numbering at zero).

LBound returns to variable the smallest subscript available in the array named array_name.

A typical use for these two functions is to define the processing limits for a loop. For example:

Dim a(4)
a(0)="1st"
a(1)="2nd"
a(3)="3rd"
a(4)="4th"
for i= LBound(a) to UBound(a)
   msgbox a(i)
next

This code would display a sequence of message boxes that display : "1st", "2nd", "3rd" and then "4th". UBound would be 3 and LBound would be 0.

.length (array version)

usage is:

variable = array_name.length;

variable is assigned an integer which is the length (number of elements) of array_name (i.e., the number of elements in array_name). Note that this is NOT the largest index of array_name. As the javascript arrays are zero-based (i.e., the first array element has an index of zero), the largest array element has an index of array_name.length - 1.

Join

usage is:

string = Join (array_name, delimiter)

Concatenates all the elements of the array_name into a single string.

array_name is the name of a single dimension array. delimiter is optional -- if supplied this string is used in the result to separate each of the elements of the array. If delimiter is NOT provided the space character is used to separate the items. If delimiter is a zero length string, the elements are NOT separated.

e.g.,

Dim a(4)
a(0)="a"
a(1)="b"
a(2)="c"
a(3)="d"
fred = Join (a)

fred gets assigned the value "a b c d"

Join

usage is:

string = array_name.join (delimiter);

Concatenates all the elements of the array_name into a single string.

array_name is the name of a single dimension array. delimiter is optional -- if supplied this string is used in the result to separate each of the elements of the array. If delimiter is NOT provided a comma is used to separate the items. If delimiter is a zero length string, the elements are NOT separated.

  e.g.,

var a = new Array(4)
a[0]="a"
a[1]="b"
a[2]="c"
a[3]="d"
fred = a.join()

fred gets assigned the value "a,b,c,d"

  Filter

  usage is:

  array_name_2 = Filter ( array_name_1 , string , include )

  Filter searches an array specified as the first argument (i.e., array_name_1) looking for array elements that contain the second argument string. For each element of array_name_1 that contains string, a copy is made an placed in array_name_2. include is optional -- if true the Filter returns elements that DO CONTAIN string; if include is false the Filter returns elements that DO NOT CONTAIN string. Default for include is true.

 
  concat

  usage is:

array-1.concat ( item-1, item-2, item-3, ... );

.concat attaches to the end of array-1 the items provided in the argument list in sequence. An item may be an array.

  e.g.,

var a = new Array ();
var b = new Array ();
a[0]="1";
a[1]="2";
a[2]="3";
a[3]="4";
b[0]="8";
b[1]="9";
a.concat("5","6","7",b);

after the .concat, a contains:

a[0]="1";
a[1]="2";
a[2]="3";
a[3]="4";
a[4]="5";
a[5]="6";
a[6]="7";
a[7]="8";
a[9]="9";

  slice

  usage is:

var array_2 = array-1.slice ( beginning-element , ending-element );

.slice returns a new array whose zeroth element from array-1's beginning-element element. This process continues up to BUT NOT including array-1's ending-element. If the ending-element is specified as a negative number, the process stops at this value from the end of the array (i.e.,
if ending-element = -1, the last element is NOT copied to array_2;
if ending-element = -2, the last two elements are NOT copied to array_2;
if ending-element = -3, the last three elements are NOT copied to array_2,...

if ending-element is not specified, all elements from beginning-element to the end of array-1 are copied to array_2. The original contents of array-1 are not modified or destroyed.

  e.g.,

var a = new Array (); a[0]="1";
a[1]="2";
a[2]="3";
a[3]="4";
a[4]="5";
a[5]="6";
a[6]="7";
a[7]="8";
a[8]="9";
var b = a.slice(1,4);
var c = a.slice(4,-2);

this code produces:

b[0]="2";
b[1]="3";
b[2]="4";

  and
c[0]="5";
c[1]="6";
c[2]="7";

  reverse

  usage is:

array.reverse ();

.reverse swaps the order of the elements of array. The first (index value = 0) becomes the last; the second (index value = 1) becomes the next-to last; ... ;the next-to-last becomes the second (index value = 1); and the last becomes the first (index value = 0).

  e.g.,

var a = new Array ();
a[0]="1";
a[1]="2";
a[2]="3";
a[3]="4";
a[4]="5";
a[5]="6";
a[6]="7";
a[7]="8";
a[8]="9";
a.reverse();

this code produces:

a[0]=9
a[1]=8
a[2]=7
a[3]=6
a[4]=5
a[5]=4
a[6]=3
a[7]=2
a[8]=1

 
  Date and Time Operations 
 
VBScript FunctionsJavascript Properties and Methods
What is the Time and Date?
  • Time

    usage is:

    string = cstr(Time)

    returns the current time in
    HH:MM:SS format with AM or PM at the end

    e.g.,

    curtime = cstr(Time)
    returns the string "9:41:26 AM" to the variable curtime

  • Date

    usage is:

    string = cstr(Date)

    returns the current date in
    MM/DD/YYYY format

    e.g.,

    curdate = cstr(Date)
    returns the string "5/1/2009" to the variable curdate

  • Time and Date

    usage is:

    string = cstr(Now)

    returns the current time and date in
    MM/DD/YYYY HH:MM:SS format followed by AM or PM

    e.g.,

    curtimedate = cstr(Now)
    returns the string "5/1/2009 9:51:10 AM" to the variable curtimedate

  • Month

    usage is:

    string = cstr( Month(Date)) )

    returns the number of the current month (1,2,3,...12). Note that one passes the current "Date" to the function.

    e.g.,
    curmonth = cstr( Month(Date)) )

    returns the string "5" to the variable curmonth

  • Month Name

    usage is:

    string = cstr( MonthName ( Month(Date) ) )

    returns the name of the current month. MonthName requires the number of the month as an argument -- so you first must first get the number of the month using the Month function, which uses the Date as an argument.

    e.g.,
    curmonthname = MonthName ( Month(Date))

    returns a string with the name of the month to the variable curmonthname

  • Day

    usage is:

    string = cstr( Day ( Date) )

    returns the number of the current day of the month (1,2,3,...30,31). Day uses the Date as an argument.

    e.g.,
    curdaynumber = cstr( Day(Date) )

    returns a string with the number of the current day of the month to the variable curdaynumber

  • Weekday

    usage is:

    string = Weekday ( Date) )

    returns the number of the current day of the week (1,2,3,4,5,6, or 7). Weekday uses the Date as an argument.

    e.g.,
    dayoftheweeknumber = cstr( Weekday(Date) )

    returns a string with the number of the current day of the week to the variable dayoftheweeknumber

  • WeekdayName

    usage is:

    string = WeekdayName ( WeekDay(Date) )

    returns the name of the current day of the week (Monday, Tuesday...Sunday). WeekdayName uses the number of the day of the week as an argument. So, you first must be this number from WeekDay(Date).

    e.g.,
    dayname = WeekdayName( Weekday(Date) )

    returns a string with the name of the current day of the week to the variable dayname

  • Year

    usage is:

    string = cstr( Year(Date) ) )

    returns the number of the current year from Date.

    e.g.,
    yearnumber = cstr( Year( Date) )

    returns a string with the number of the current year to the variable yearnumber

  • Hour

    usage is:

    string = cstr( Hour( Time) )

    returns the number of the current hour (0,1,2,...23) from Time.

    e.g.,
    hournumber = cstr( Hour( Time) )

    returns a string with the number of the current hour to the variable hournumber

  • Minute

    usage is:

    string = cstr( Minute( Time) )

    returns the number of the current minute (0,1,2,...59) from Time.

    e.g.,
    minutenumber = cstr( Minute( Time) )

    returns a string with the number of the current minute to the variable minutenumber

  • Second

    usage is:

    string = cstr( Second( Time) )

    returns the number of the current second (0,1,2,...59) from Time.

    e.g.,
    secondnumber = cstr( Second( Time) )

    returns a string with the number of the current second to the variable secondnumber

  • DateDiff

    usage is:

    string = cstr( DateDiff( Interval Type, earlier date, later date, First Day of the Week, First Week of the Year )

    returns the difference in earlier date and later date expressed in Interval Type. Interval Type can be:

    • "yyyy" calculation in years
    • "q" calculation in quarters
    • "m" calculation in months
    • "y" calculation in day of the year
    • "d" calculation in days
    • "w" calculation in weekdays
    • "ww" calculation in weeks of the year
    • "h" calculation in hours
    • "n" calculation in minutes
    • "s" calculation in seconds

    First Day of the Week is optional and defines what is to be considered the first day of the week. Possible values are: 1=Sun (default), 2=Mon, 3=Tue, 4=Wed, 5=Thu, 6=Fri, and 7=Sat. This is relative to interval types = "w" or "ww"

    First Week of the Year is optional and defines how the first week of the year is defined. Values are: 0=system assumption, 1=week where Jan 1 occurs (default), 2=start with the first week that has at least four days, 3=starts with the first full week of the year (i.e., the weekfirst week with seven days).

    returns a string with the number of the interval type specified. Note: if earlier date occurs AFTER later date values returned are negative.

    e.g., using
    d1="5/1/2009 9:51:10 AM"
    d2="5/2/2010 10:52:11 AM"
    (these dates differ by one year, one day, one hour, one minute and one second)
    The following results when DateDiff (various, d1, d2) is evaluated for ALL the various values of Interval Type:

    Diff in years (interval type='yyyy')=1
    Diff in quarters (interval type='q')=4
    Diff in months (interval type='m')=12
    Diff in day of year (interval type='y)=366
    Diff in days (interval type='d')=366
    Diff in weekdays (interval type='w')=52
    Diff in weeks of the year (interval type='ww')=53
      (note 5/2/2011 is a Sunday, so it is a new (one more)
       week as compared to the "w" measure above)
    Diff in hours (interval type='h')=8785 (i.e., 366*24+1)
    Diff in minutes (interval type='n')=527101 (i.e., 8785*60+1)
    Diff in seconds (interval type='s')=31626061 (i.e., 527101*60+1)

  • DateAdd

    usage is:

    string = cstr( DateAdd( Interval Type, value, date )

    returns the date/time that results from adding value expressed in Interval Type to the date. Interval Type can be:

    • "yyyy" calculation in years
    • "q" calculation in quarters
    • "m" calculation in months
    • "y" calculation in day of the year
    • "d" calculation in days
    • "w" calculation in weekdays
    • "ww" calculation in weeks of the year
    • "h" calculation in hours
    • "n" calculation in minutes
    • "s" calculation in seconds

    returns a string with the new date.

    e.g., using d="5/1/2009 9:51:10 AM"
    The following results when DateAdd (various, 1, d) is evaluated for ALL the various values of Interval Type:

    Add 1 year (interval type='yyyy')5/1/2010 9:51:10 AM
    Add 1 quarter (interval type='q')8/1/2009 9:51:10 AM
    Add 1 month (interval type='m')6/1/2009 9:51:10 AM
    Add 1 day of year (interval type='y)5/2/2009 9:51:10 AM
    Add 1 day (interval type='d')5/2/2009 9:51:10 AM
    Add 1 weekday (interval type='w')5/2/2009 9:51:10 AM
    Add 1 week of the year (interval type='ww')5/8/2009 9:51:10 AM
    Add 1 hour (interval type='h')5/1/2009 10:51:10 AM
    Add 1 minute (interval type='n')5/1/2009 9:52:10 AM
    Add 1 second (interval type='s')5/1/2009 9:51:11 AM

  • DatePart

    usage is:

    string = cstr( DatePart( Interval Type, date, First Day of the Week, First Week of the Year )

    returns the part of date specified by Interval Type. Interval Type can be:

    • "yyyy" calculation in years
    • "q" calculation in quarters
    • "m" calculation in months
    • "y" calculation in day of the year
    • "d" calculation in days
    • "w" calculation in weekdays
    • "ww" calculation in weeks of the year
    • "h" calculation in hours
    • "n" calculation in minutes
    • "s" calculation in seconds

    First Day of the Week is optional and defines what is to be considered the first day of the week. Possible values are: 1=Sun (default), 2=Mon, 3=Tue, 4=Wed, 5=Thu, 6=Fri, and 7=Sat. This is relative to interval types = "w" or "ww"

    First Week of the Year is optional and defines how the first week of the year is defined. Values are: 0=system assumption, 1=week where Jan 1 occurs (default), 2=start with the first week that has at least four days, 3=starts with the first full week of the year (i.e., the weekfirst week with seven days).

    e.g., using DatePart(interval type,"5/1/2009 9:51:10 AM"), the following results from using all the various interval types:

    DatePart in years (interval type='yyyy')=2009
    DatePart in quarters (interval type='q')=2
    DatePart in months (interval type='m')=5
    DatePart in days of year (interval type='y)=121
    DatePart in days (interval type='d')=1
    DatePart in weekdays (interval type='w')=6 (5/1/2009 is a Friday)
    DatePart in weeks of the year (interval type='ww')=18
    DatePart in hours (interval type='h')=9
    DatePart in minutes (interval type='n')=51
    DatePart in seconds (interval type='s')=10

  • DateSerial

    usage is:

    string = cstr( DateSerial( year, month, day)

    returns a formatted date with the specified year, month and day.

    e.g., string = cstr( DateSerial( 2009, 5, 10) )

    returns "5/10/2009"

  • DateValue

    usage is:

    string = cstr( DateValue( string)

    returns a formatted date with the specified string whenever string is a valid date. If Time is included it is NOT returned. If a year is omitted, the function supplies the current date's value.

    e.g.,

    DateValue('5/10/2009') returns 5/10/2009
    DateValue('May 10 2009') returns 5/10/2009
    DateValue('May 10 2009 12:22;59') returns 5/10/2009
    DateValue('5-10-2009') returns 5/10/2009
    DateValue('May 10') returns 5/10/2009
    (this was executed on 5/4/2009 and supplies the 2009 part)

What is the Time and Date?

Dates and Time in javascript are based on accessing you computer's current data and time through the creation of a Date object as:

var date_time_object = new Date ()

The value returned is in: DDD MMM dd hh:mm:ss tmz YYYY

where:

  • "DDD" is a three character alphabetic day name (e.g., Mon, Tue,...);
  • "MMM" is a three character month name (Jan, Feb, ...);
  • "dd" is a one or two digits day (1,2,...,30,31);
  • "hh" is a one or two digits hour based on a 24 clock;
  • "mm" is the two digit minute;
  • "ss" is the two digit seconds;
  • "tmx" is the three character time zone
    (in the US: EST( or EDT); CST (or CDT); MST (or MDT); or PST (or PDT) -- the "D" or "S" depending on whether "daylight savings time" is in effect.

e.g.,
Fri May 1 10:05:15 CDT 2009
Thu May 21 17:05:15 PDT 2009
Tue Dec 1 6:05:15 PST 2009

Most of the following methods use the Date object you create to "get" or "set" one of the parts of the Date object.

  • getDate() or setDate()

    usage is:

    date_time_object.getDate();
    or
    date_time_object.setDate();

    returns (gets) or assigns (sets) the number of the day of the month (1,2,3,...31) of the date_time_object.

  • getDay() or setDay()

    usage is:

    date_time_object.getDay();
    or
    date_time_object.setDay();

    returns (gets) or assigns (sets) the number day of the week (0,1,2,3,...6) of the date_time_object. Sunday=0, Monday=1,...Saturday=6.

  • getFullYear() or setFullYear()

    usage is:

    date_time_object.getFullYear();
    or
    date_time_object.setFullYear();

    returns (gets) or assigns (sets) the four digit number of the year of the date_time_object.

  • getYear() or setYear()

    usage is:

    date_time_object.getYear();
    or
    date_time_object.setYear();

    returns (gets) or assigns (sets) the number of the year (Internet Explorer returns 2 digits if from 1900-1999, otherwise 4 digits; Firefox returns 0 for 1900, -100 for 1800, -200 for 1700, etc,; 0 to 99 for between 1900 and 1999; 100 to 199 between 2000 and 2099 etc.) of the date_time_object. You should use FullYear above instead.

  • getMonth() or setMonth()

    usage is:

    date_time_object.getMonth();
    or
    date_time_object.setMonth();

    returns (gets) or assigns (sets) the number of the month (0,2,3,...,11) of the date_time_object. January=0, February=1,...December=11)

  • getHours() or setHours()

    usage is:

    date_time_object.getHours();
    or
    date_time_object.setHours();

    returns (gets) or assigns (sets) the number of the hour (0,2,3,...,23) of the date_time_object.

  • getMinutes() or setMinutes()

    usage is:

    date_time_object.getMinutes();
    or
    date_time_object.setMinutes();

    returns (gets) or assigns (sets) the number of the minutes (0,2,3,...,59) of the date_time_object.

  • getSeconds() or setSeconds()

    usage is:

    date_time_object.getSeconds();
    or
    date_time_object.setSeconds();

    returns (gets) or assigns (sets) the number of the seconds (0,2,3,...,59) of the date_time_object.

  • getMilliseconds() or setMilliseconds()

    usage is:

    date_time_object.getMilliseconds();
    or
    date_time_object.setMilliseconds();

    returns (gets) or assigns (sets) the number of the milliseconds (0,2,3,...,999) of the date_time_object.

  • getTime() or setTime()

    usage is:

    date_time_object.getTime();
    or
    date_time_object.setTime();

    returns (gets) or assigns (sets) the number milliseconds since midnight of January 1, 1970 of the date_time_object.

Using a date field, the example below shows the .gettime/date property() values. In IE getDate is:

Fri May 1 14:01:24 CDT 2009

Firefox says:

Fri May 01 2009 14:06:50 GMT-0500 (Central Daylight Time)

getDate() is 1
getDay() is 5
getFullYear() is 2009
getYear() is 2009 in IE
   firefox says: "109" instead

getMonth() is 4
getHours() is 14
getMinutes() is 1
getSeconds() is 24
getMilliseconds() is 43
getTime() is 1241204484043

Month and Day names have to be constructed by using additional code as do "AM" or "PM".

Javascript Time Difference
 

Usage:

We will use two date/time objects like this:

var date_time_object_name = new Date();

To get the current time the date/time object name use:

local variable = date_time_object_namegetTime();

The local variable will contain the number of milliseconds (an integer) from midnight of January 1, 1970 (12:00:00:000 AM) to the time the date_time object name object was created.

Try it here:

Elapsed Time between clicking "me first" and "me second" is:  

 

Javascript code