Date Helper
The Date Helper file contains handlers that help you work with dates.
Loading this Helper
This helper is loaded using the following code:
rigLoadHelper "date"
The following handlers are available:
rigNow()
Returns the current time as a timestamp (seconds), referenced either to your server's local time or GMT, based on the "time reference" setting in your config file. If you do not intend to set your master time reference to GMT (which you'll typically do if you run a site that lets each user set their own timezone settings) there is no benefit to using this function over LiveCode's seconds() function.
rigMdate(dateString, time)
This function lets you use MySQL style date codes, where each code letter is preceded with a percent sign: %Y %m %d etc. Example:
put "Year: %Y Month: %m Day: %d - %h:%i %p" into tDateString
put the seconds into tTime
put rigMdate(tDateString, tTime) into gData["mdate"]
If a timestamp (seconds) is not included in the second parameter the current time will be used.
Supported specifiers:
Specifier | Description |
---|---|
%a | Abbreviated weekday name (Sun..Sat) |
%b | Abbreviated month name (Jan..Dec) |
%c | Month, numeric (0..12) |
%D | Day of the month with English suffix (0th, 1st, 2nd, 3rd, ...) |
%d | Day of the month, numeric (00..31) |
%e | Day of the month, numeric (0..31) |
%H | Hour (00..23) |
%h | Hour (01..12) |
%I | Hour (01..12) |
%i | Minutes, numeric (00..59) |
%j | Day of year (001..366) |
%k | Hour (0..23) |
%l | Hour (1..12) |
%M | Month name (January..December) |
%m | Month, numeric (00..12) |
%O | Difference to Greenwich time (GMT) in hours |
%p | AM or PM |
%r | Time, 12-hour (hh:mm:ss followed by AM or PM) |
%S | Seconds (00..59) |
%s | Seconds (00..59) |
%T | Time, 24-hour (hh:mm:ss) |
%U | Week (00..53), where Sunday is the first day of the week |
%u | Week (00..53), where Monday is the first day of the week |
%W | Weekday name (Sunday..Saturday) |
%w | Day of the week (0=Sunday..6=Saturday) |
%Y | Year, numeric, four digits |
%y | Year, numeric (two digits) |
%% | A literal “%” character |
Note: The text generated by this function is found in the following language file: language/<yourLang>/dateLang.lc
rigStandardDate(format, time)
Lets you generate a date string in one of several standardized formats. Example:
put the seconds into tTime
put "DATE_ISO8601" into tFormat
put rigStandardDate(tFormat, tTime) into gData["standardDate"]
Parameters
- format: must contain the format
- time: must contain the date as a timestamp (seconds)
Supported formats:
Constant | Description | Example |
---|---|---|
DATE_ATOM | Atom | 2005-08-15T16:13:03+00:00 |
DATE_COOKIE | HTTP Cookies | Sunday, 14 Aug 2005 16:13:03 UTC |
DATE_ISO8601 | ISO-8601 | 2005-08-14T16:13:03+0000 |
DATE_RFC822 | RFC 822 | Sun, 14 Aug 2005 16:13:03 +0000 |
DATE_RFC850 | RFC 850 | Sunday, 14-Aug-05 16:13:03 UTC |
DATE_RFC1036 | RFC 1036 | Sun, 14 Aug 05 16:13:03 +0000 |
DATE_RFC1123 | RFC 1123 | Sun, 14 Aug 2005 16:13:03 +0000 |
DATE_RFC2822 | RFC 2822 | Sun, 14 Aug 2005 16:13:03 +0000 |
DATE_RSS | RSS | Sun, 14 Aug 2005 16:13:03 +0000 |
DATE_W3C | World Wide Web Consortium | 2005-08-14T16:13:03+00:00 |
rigLocalToGMT(time)
Takes a timestamp (seconds) as input and returns it as GMT. If no parameter is provided, a timestamp of the current time is used. Example:
put rigLocalToGMT() into gData["localToGMT"]
rigGmtToLocal(time, timeZone, DST)
Takes a timestamp (seconds) (referenced to GMT) as input, and converts it to a localized timestamp based on the timezone and Daylight Saving time submitted. Example:
put "1273254973" into tTimestamp
put rigGmtToLocal(tTimestamp, "UM4", TRUE) into gData["gmtToLocal"]
Note: For a list of timezones see the reference at the bottom of this page.
rigMysqlTimeToSeconds(mysqlTime)
Takes a MySQL Timestamp as input and returns it as seconds. Example:
put "20061124092345" into tMysql
put rigMysqlTimeToSeconds(tMysql) into gData["mysqlToSeconds"]
rigTimestampToHuman(time, showSecs, format)
Takes a timestamp (seconds) as input and returns it in a human readable format with this prototype:
YYYY-MM-DD HH:MM:SS AM/PM
This can be useful if you need to display a date in a form field for submission.
The time can be formatted with or without seconds, and it can be set to European ("eu") or US format ("us"). If only the timestamp is submitted it will return the time without seconds formatted for the U.S. Examples:
put "1273254973" into tTimestamp
put rigTimestampToHuman(tTimestamp) into gData["timestampToHuman"] -- U.S. time, no seconds
put rigTimestampToHuman(tTimestamp, TRUE, "eu") into gData["timestampToHuman"] -- Euro time with seconds
put rigTimestampToHuman(tTimestamp, TRUE, "us") into gData["timestampToHuman"] -- U.S. time with seconds
rigHumanToTimestamp(datestring)
The opposite of the above function. Takes a "human" time as input and returns it as timestamp. This function is useful if you accept "human" formatted dates submitted via a form. Returns FALSE if the date string passed to it is not formatted as indicated above. Example:
put "2010-05-07 09:18:22 AM" into tDatestring
put rigHumanToTimestamp(tDatestring) into gData["humanToTimestamp"]
rigTimespan(seconds, time)
Formats a timestamp (seconds) so that is appears similar to this:
1 Year, 10 Months, 2 Weeks, 5 Days, 10 Hours, 16 Minutes
Parameters
- seconds: must contain a timestamp
- time: (optional) must contain a timestamp that is greater than the first timestamp, if this parameter is empty, the current time will be used
The most common purpose for this function is to show how much time has elapsed from some point in time in the past to now. Example:
put rigTimespan("1083241902", "1273234277") into gData["timespan"]
Note: The text generated by this function is found in the following language file: language/<yourLang>/dateLang.lc
rigDaysInMonth(month, year)
Returns the number of days in a given month/year. Takes leap years into account. Example:
put rigDaysInMonth("2", "2010") into gData["daysInMonth"]
If the second parameter is empty, the current year will be used.
rigTimezones(timeZone)
Takes a timezone reference (for a list of valid timezones, see the "Timezone Reference" below) and returns the number of hours offset from UTC.
put rigTimezones("UM5") into gData["timezone"]
This function is useful when used with rigTimezoneMenu().
rigTimezoneMenu(default, class, name)
Generates a pull-down menu of timezones, like this one:
This menu is useful if you run a membership site in which your users are allowed to set their local timezone value.
The first parameter lets you set the "selected" state of the menu. For example, to set Brazil time as the default you will do this:
put rigTimezoneMenu("UM9", "tzClass", "tzName") into gData["timezoneMenu"]
Please see the timezone reference below to see the values of this menu.
The second parameter lets you set a CSS class name, the third a name for the menu.
Note: The text contained in the menu is found in the following language file: language/<yourLang>/dateLang.lc
Timezone Reference
The following table indicates each timezone and its location.
Time Zone | Location |
---|---|
UM12 | (UTC - 12:00) Enitwetok, Kwajalien |
UM11 | (UTC - 11:00) Nome, Midway Island, Samoa |
UM10 | (UTC - 10:00) Hawaii |
UM9 | (UTC - 9:00) Alaska |
UM8 | (UTC - 8:00) Pacific Time |
UM7 | (UTC - 7:00) Mountain Time |
UM6 | (UTC - 6:00) Central Time, Mexico City |
UM5 | (UTC - 5:00) Eastern Time, Bogota, Lima, Quito |
UM4 | (UTC - 4:00) Atlantic Time, Caracas, La Paz |
UM25 | (UTC - 3:30) Newfoundland |
UM3 | (UTC - 3:00) Brazil, Buenos Aires, Georgetown, Falkland Is. |
UM2 | (UTC - 2:00) Mid-Atlantic, Ascention Is., St Helena |
UM1 | (UTC - 1:00) Azores, Cape Verde Islands |
UTC | (UTC) Casablanca, Dublin, Edinburgh, London, Lisbon, Monrovia |
UP1 | (UTC + 1:00) Berlin, Brussels, Copenhagen, Madrid, Paris, Rome |
UP2 | (UTC + 2:00) Kaliningrad, South Africa, Warsaw |
UP3 | (UTC + 3:00) Baghdad, Riyadh, Moscow, Nairobi |
UP25 | (UTC + 3:30) Tehran |
UP4 | (UTC + 4:00) Adu Dhabi, Baku, Muscat, Tbilisi |
UP35 | (UTC + 4:30) Kabul |
UP5 | (UTC + 5:00) Islamabad, Karachi, Tashkent |
UP45 | (UTC + 5:30) Bombay, Calcutta, Madras, New Delhi |
UP6 | (UTC + 6:00) Almaty, Colomba, Dhaka |
UP7 | (UTC + 7:00) Bangkok, Hanoi, Jakarta |
UP8 | (UTC + 8:00) Beijing, Hong Kong, Perth, Singapore, Taipei |
UP9 | (UTC + 9:00) Osaka, Sapporo, Seoul, Tokyo, Yakutsk |
UP85 | (UTC + 9:30) Adelaide, Darwin |
UP10 | (UTC + 10:00) Melbourne, Papua New Guinea, Sydney, Vladivostok |
UP11 | (UTC + 11:00) Magadan, New Caledonia, Solomon Islands |
UP12 | (UTC + 12:00) Auckland, Wellington, Fiji, Marshall Island |