WebSiphon 2 Guide: Date and Time Functions
contents prev next

In WebSiphon 2, Date and Time values are expressed as specially formatted strings:

time-valueHH:MM:SS AM/PM
date-valueMM/DD/YYYY
datetime-valueMM/DD/YYYY HH:MM:SS AM/PM

The functions provided in the built-in Date and Time library are used to:

currentDate
currentTime
dayOf
diffTime
formatDate
formatDateTime
formatRFC1123
formatTime
formatTimeStr
hourOf
listToTime
minuteOf
monthName
monthOf
now
nowSecs
secondsOf
secsToTime
tickCount
timeToList
timeToSecs
weekDayName
weekDayOf
yearOf
currentDate ( )
Returns: date string Location: Built-in
Returns the current date using the server's built-in clock in the format MM/DD/YYYY. Format this value for display or perform calculations using functions which accept a date-value as a parameter.

Example:

print "Today's date is " currentDate() & ".";
>> Today's date is 11/28/2000.

See Also:

currentTime ( )
Returns: time string Location: Built-in

Returns the current time using the server's built-in clock in the format HH:MM:SS AM/PM. Format this value for display or perform time calculations using functions which accept a time-value as a parameter.

Example:

print "The current time is " currentTime() & ".";
>> The current time is 04:35:28 PM.

See Also:

dayOf ( datetime-value )
Returns: integer Location: Built-in
ParameterDescription
datetime-valueformatted datetime string

Accepts a formatted datetime-value, such as is returned by now(), and returns the day-of-month segment of that value as an integer.

Example:

the_date = dayOf(now());
print the_date;

>> 28

See Also:

diffTime ( datetime-value1, datetime-value2 )
Returns: float Location: Built-in
ParameterDescription
datetime-value1(now) formatted datetime string 1
datetime-value2(then) formatted datetime string 2

Returns the difference between two datetime values in seconds. If datetime-value2 is chronologically after datetime-value1, the returned result will be negative. The result is a floating point value in order to gain the greater precision of that data type. The actual value will always be a whole number.

The example below illustrates how to compute a rough benchmark of the time required for a template to execute. It then appends the result to WebSiphon's console log window. Compare with the same operation using tickCount() which provides a more precise benchmark.

Example:

start_time = now();
// This is just an example, the actual contents of your template with 
// HTML and SiphonScript would go here.
elapsed = diffTime(now(), start_time);
appendLog(template_uri & " " & (elapsed as float(,2)) & "s exec");
formatDate ( date-value, format-string )
Returns: string Location: Built-in
ParameterDescription
date-valueformatted date string
format-stringformat specifier string

Returns the formatted date segment of the date-value parameter using the web server's localized date format setting (as specified on the server computer's OS Control Panel). The format-string parameter may be one of "long", "short", or "abbrev".

This function is used to create human-readable content, and should not be used to obtain a date value suitable for use as a paramater to other functions.

If a datetime value is provided in date-value, the time segment is ignored.

Examples:

  1. print formatDate(currentDate(), "long");
    >> Friday, September 6, 1996
  2. print formatDate(now(), "short");
    >> 9/6/96
  3. print formatDate(now(), "abbrev");
    >> Fri, Sep 6, 1996

See Also:

formatDateTime (datetime-value, format-string, want-seconds)
Returns: string Location: Built-in
ParameterDescription
datetime-valueformatted datetime string
format-stringformat specifier string
want-secondsinclude seconds in output? (true/false)

Provided a datetime-value, returns a formatted datetime string using the web server's localized datetime format setting (as specified on the server computer's OS Control Panel). The format-string parameter may be one of "long", "short", or "abbrev". The want-seconds boolean indicates whether or not to include the seconds in the returned output.

This function is used to create human-readable content, and should not be used to obtain a datetime value suitable for use as a paramater to other functions.

Examples:

  1. print formatDateTime(now(), "long", true);
    >> Tuesday, November 28, 2000 4:25:11 PM
  2. print formatDateTime(now(), "abbrev", true);
    >> Tue, Nov 28, 2000 4:25:11 PM
  3. print formatDateTime(now(), "short", true);
    >> 11/28/00 4:25:11 PM

See Also:

formatRFC1123 ( datetime-value )
Returns: string Location: Built-in
ParameterDescription
datetime-valueformatted datetime string

Given a datetime-value, first converts to a Greenwich Mean Time (GMT, or UT) value and then returns an RFC1123-formatted datetime string as a result.

Note that if you need a datetime string suitable for use as an HTTP cookie expiration value, then you'll need to further modify this value to include dashes within the date as a delimiter. Refer to setCookie()'s documentation for further details.

Example:

print formatRFC1123("11/03/1997 12:01:15 PM");
>> Mon, 03 Nov 1997 18:01:15 GMT

See Also:

formatTime ( time-value, want-seconds )
Returns: string Location: Built-in
ParameterDescription
timeformated time string
want-secondsinclude seconds in output? (true/false)

Returns the formatted time segment of the time-value parameter using the web server's localized time format setting (as specified on the server computer's OS Control Panel). The want-seconds boolean indicates whether or not to include the seconds in the returned output.

This function is used to create human-readable content, and should not be used to obtain a time value suitable for use as a parameter to other functions.

If a datetime value is provided in time-value, the date segement is ignored.

Examples:

print formatTime(currentTime(), true);
>> 6:23:07 PM

print formatTime(now(), false);
>> 6:23 PM

See Also:

formatTimeStr ( datetime-value, format-string )
Returns: string Location: Built-in
ParameterDescription
timeformatted datetime string
formatformat specifier string (see table)

For those who need utmost control in formatting datetime values, this very flexible though somewhat cryptic function returns the formatted datetime-value parameter as specified in the format-string. The format parameter may contain any combination of the specifier strings listed in the table below.

Valid string specifier tokens for format-string:

SpecifierFormatted As
%aabbreviated weekday name
%Afull weekday name
%babbreviated month name
%Bfull month name
%dday of the month as a decimal number (01 - 31)
%Hhour (24-hour clock), as a decimal number (00 - 23)
%Ihour (12-hour clock), as a decimal number (01 - 12)
%jday of the year, as a decimal number (001 - 366)
%mmonth, as a decimal number (01 - 12)
%Mminute, as a decimal number (00 - 59)
%pAM/PM designation for a 12-hour clock
%Ssecond, as a decimal number (00 - 59)
%Uweek number of the year (with Sunday as the first day of the first week), as a decimal number (00 - 53)
%wweekday, as a decimal number (0 [Sunday] - 6 [Saturday])
%Wweek number of the year (with Monday as the first day of the first week), as a decimal number (00 - 53)
%yyear without century, as a decimal number (00 - 99)
%Yyear with century, as a decimal number
%%%

Example:

print formatTimeStr(now(), "%A, %B %d, %Y %I:%M:%S %p");
>> Friday, September 6, 1996 06:23:07 PM
hourOf ( time-value )
Returns: integer Location: Built-in
ParameterDescription
time-valueformatted time string

Returns the hour segment of time-value as an integer. The returned value is based on a 24-hour clock, so values less than 12 are considered AM and values greater than 12 are PM.

Example:

the_hour = hourOf(now());
print the_hour;

>> 14
listToTime ( datetime-list )
Returns: datetime string Location: Built-in
ParameterDescription
datetime-lista structured list of datetime fields (see table below)

Converts a structured list containing the individual datetime fields into a formatted datetime string suitable for passing to other date and time functions (in the format "MM/DD/YYYY HH:MM:SS AM/PM").

The datetime-list parameter is a list with the following structure:

List ItemField
1year with century, as a decimal number
2month, as a decimal number (01 - 12)
3day of month, as a decimal number (01 - 31)
4hour, as a decimal number (00 - 23)
5minute, as a decimal number (00 - 59)
6second, as a decimal number (00 - 59)
...all additional list items are ignored

See Also:

minuteOf ( time-value )
Returns: integer Location: Built-in
ParameterDescription
time-valueformatted time string

Returns the minute segment of time-value as an integer.

Example:

the_minute = minuteOf(now());
print the_minute;

>> 45
monthName ( month-integer )
Returns: string Location: Built-in
ParameterDescription
month-numbernumerical month as integer (1-12)

Given a month as a number (1-12) in month-integer, this function will return the actual name of the month using the web server's localized date format setting (as specified on the server computer's OS Control Panel).

Example:

print monthName(monthOf(now()));

>> November

See Also:

monthOf ( time-value )
Returns: integer Location: Built-in
ParameterDescription
time-valueformatted time string

Returns the month segment of time-value as an integer.

Example:

the_month = monthOf(now());
print the_month;

>> 11

See Also:

now ( )
Returns: datetime string Location: Built-in

Returns a string containing the current date and time with seconds, in that order, with a space in between. The format of the returned datetime string is a standard international time string in the format MM/DD/YYYY HH:MM:SS AM/PM.

This function returns a datetime value suitable for use as a parameter to other Date and Time functions.

Example:

print "Right now it is " now() & ".";
>> Right now it is 09/03/2000 10:15:23 AM.
nowSecs ( )
Returns: float Location: Built-in

Returns the current time in seconds since January 1, 1904.

Time values expressed in seconds relative to a common point in time are helpful when you need to compute time values, such as scheduling or expiration logic.

See Also:

secondsOf ( time-value )
Returns: integer Location: Built-in
ParameterDescription
time-valueformatted time string

Returns the seconds segment of time-value as an integer.

Example:

the_seconds = secondsOf(now());
print the_seconds;

>> 47
secsToTime ( time-value-seconds )
Returns: string Location: Built-in
ParameterDescription
time-value-secondstime value, as seconds since January 1, 1904

Converts a time value in seconds since January 1, 1904 to a formatted datetime string suitable for use with any other date and time functions.

See Also:

tickCount ( )
Returns: float Location: Built-in

Returns the number of ticks (60ths of a second) since the computer was turned on. The tick count value is useful for generating pseudo-random numbers such as session IDs or recording the amount of time needed for a template to execute.

Example:

start_ticks = tickCount();
// This is just an example, the contents of your template with 
// HTML and SiphonScript would go here.
elapsed = (tickCount() - start_ticks);
seconds_elapsed = elapsed / 60;
appendLog("This template took " & (seconds_elapsed as float(,2)) & 
          " seconds to execute which is " & elapsed & " ticks.");
timeToList ( datetime-value )
Returns: datetime-list Location: Built-in
ParameterDescription
datetime-valueformatted datetime string

Converts a standard datetime string into a structured list containing the individual time and date fields. This, in conjunction with listToTime(), is a useful method of incrementing or decrementing a time value by a specific amount.

The returned datetime-list has the following structure:

List ItemField
1year with century, as a decimal number
2month, as a decimal number (01 - 12)
3day of month, as a decimal number (01 - 31)
4hour, as a decimal number (00 - 23)
5minute, as a decimal number (00 - 59)
6second, as a decimal number (00 - 59)
7day of week, as a decimal number (1 [Sunday] - 7 [Saturday])
8day of year, as a decimal number (001 - 366)
9week of year (with Sunday as the first day of the first week), as a decimal number (01 - 52)
10is PM? 0 = AM; 1 = PM

See Also:

timeToSecs ( datetime-value )
Returns: float Location: Built-in
ParameterDescription
datetime-valueformatted datetime string

Converts a standard datetime string to the number of seconds since January 1, 1904, expressed as an integer but returned as a float to gain greater precision affored by the floating point data type.

See Also:

weekDayName ( weekday-number )
Returns: string Location: Built-in
ParameterDescription
weekday-numbernumerical day as integer (1-7)

Given a weekday as a number (1-7) in weekday-number, this function will return the actual name of the weekday using the web server's localized date format setting (as specified on the server computer's OS Control Panel).

Example:

print weekDayName(weekDayOf(now()));

>> Tuesday

See Also:

weekDayOf ( datetime-value )
Returns: integer Location: Built-in
ParameterDescription
datetime-valueformatted datetime string

Returns the week day segment of datetime-value. Rather than returning the actual date as in dayOf(), this function returns the week day number (1 [Sunday] - 7 [Saturday]) as an integer.

Example:

the_weekday = weekDayOf(now());
print the_weekday;

>> 3

See Also:

yearOf ( datetime-value )
Returns: integer Location: Built-in
ParameterDescription
datetime-valueformatted datetime string

Returns the year segment of datetime-value as an integer.

Example:

the_year = yearOf(now());
print the_year;

>> 1997

contents prev next Copyright (c)1996-2003 Purity Software