Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Date and Time Functions

Handling date and time variables can be somewhat tricky, especially when you’re using the SQL calls, in which case they have to be in a format that ODBC can interpret correctly. CFML supports 31 functions that operate on date and time variables. The following list provides a sampling of these functions. If you specify a year quantity less than 100, it is interpreted as a twentieth century value.

  CreateDateTime(year,month,day,hour,minute,second)—Creates a date/time variable with the value corresponding to the year, month, day, hour, minute, and second information provided.
  CreateODBCDateTime(year,month,day,hour,minute,second)—Creates a date/time variable in ODBC format with the value corresponding to the year, month, day, hour, minute, and second information provided.
  DateCompare(datetime1,datetime2)—Compares datetime1 and datetime2 and returns -1 if datetime1 is less than datetime2, 0 if datetime1 equals datetime2, and 1 if datetime1 is greater than datetime2.
  Day(date)—Returns the day of the month (1–31) on which that date falls.
  Hour(date)—Returns the hour (0–23) specified by date.
  IsDate(‘variable’)—Returns TRUE if variable is a valid date/time variable or FALSE if variable is not.
  IsLeapYear(year)—Returns TRUE if year is a leap year or FALSE if year is not.
  Minute(date)—Returns the value of the minutes (0 –59) specification in the variable date.
  Month(date)—Returns the numeric value of the month (1–12) in the variable date.
  Now()—Returns the current system date and time.

The Now() function makes it easy to timestamp database transactions.

  ParseDateTime(str)—Converts the string str to a valid date/time variable.
  Second(date)—Returns the value of the seconds (0 –59) specification in the variable date.
  Week(date)—Returns the numerical week of the year (1–53) during which date occurs.
  Year(date)—Returns the value of the year specification in the variable date.

Math Functions

You may not need to do much mathematical computation as part of your ColdFusion applications, but CFML includes a large library of math functions for you to use when the need arises. Some of these include:

  Abs(num)—Returns the absolute value of num.
  Ceiling(num)—Returns the closest integer bigger than num.
  DecrementValue(num)—Subtracts one from the value of num.
  IncrementValue(num)—Adds one to the value of num.
  Int(num)—Returns the closest integer smaller than num.
  Log(num)—Returns the natural logarithm of num.
  Log10(num)—Returns the base-10 logarithm of num.
  Max(num1,num2)—Returns the larger of num1 and num2.
  Min(num1,num2)—Returns the smaller of num1 and num2.
  pi()—Returns the value of the constant pi, 3.14159265358979. pi represents the ratio of the circumference of a circle to its diameter.
  Rand()—Returns a random number between 0 and 1.
  RandRange(num1,num2)—Returns a random number between num1 and num2.
  Round(num)—Rounds num to the closest integer.
  Sgn(num)—Returns -1 if num is negative, 0 if num is zero, and 1 if num is positive.
  Sqr(num)—Returns the positive square root of num.

Two Other Useful Functions

Two other valuable functions should be part of your basic ColdFusion awareness:

  IsDefined(‘variable’)—Returns TRUE if variable is defined and FALSE if it is not defined.
  URLEncodedFormat(str)—Converts str so that it can be passed to the next template as a URL variable.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.