About Date and Time Functions
You can represent dates and times as native types and manipulate them using a set of
specific date/time functions. Both dates and times are saved using a data type called a
"date/time value". The underlying representation of a date or time is the same, but the
format is different. A date/time value has different parts, including a year, a month, a day
of the month, hours, minutes, seconds. Additionally, a format field describes how to
translate these elements into a string. It is not required to define all of these fields. To
represent a "date", the value contains a year, month, and day of the month (for example, "23
July 1957"). To represent a "time", the value contains an hour, a minute, and possibly a
second (for example, "12:33:05").
You may need to create a date/time value from the interpretation of a string such as "Tue,
March 03, 2006" or "12:04:00 PM". When you leave parts of a date/time value undefined, Pipeline Creator uses defaults as required. For example, the current date for undefined date fields, noon
(12:00:00) for undefined time fields, and the universal time-zone UTC. You can derive other
attributes from these fields such as the day of the week (Wednesday) or the Julian date
(2436043.18056).
You can convert date/time information to several useful forms. If you want to sort dates
with different input formats, convert date/time values to numbers and to return the Julian
date. Convert date/time values to strings using a format string. By default, the format
string is derived from the input string, but you can change it to another format if
required.
It is not required to define all fields in a date/time value. For example, if you define a
date using the string "23 July", this defines the day of the month and the month, but not
the year, hour, minute, and second. This will be invisible, but if you change the output
format, you may see undefined fields printed as a sequence of asterisks (****). Functions
that require definition of all fields (such as the calculation of a Julian date)
automatically fill in undefined fields using the corresponding field value from Julian date
zero (January 1, -4713 BCE, 12:00:00.000 UTC). You can use the function
DateFillUndefined() to fill in undefined fields using the current date
and time.
You can use date/time values in many useful ways. For example, you can:
- Join using dates, for
JoinPropertyType specify
"IsDate".
- Sort on dates either by performing a numeric sort on Julian dates or using
SortAs function set to "AsDates".
- Merge records using dates.
You can also perform these operations using partial dates (for example, using a date
containing only the day of the month and the month, as in "12-Mar"). A detailed description
of these uses for date/time values is beyond the scope of this document which focuses on the
manipulation of dates and times within PilotScript.
The only difference between "dates", "times", and "date/time values", is with their format.
All the date/time functions described in this document work on any of these properties. The
terms "date" and "time" help you to create them with appropriate formatting.
Data and Time Formats
When you specify a format for a date or time value, use these definitions with the order
and separators that you require:
- %c: localized date and time format.
- %Y: four-digit year.
- %y: two-digit year.
- %m: month as a two-digit number with leading zero, such as 01 for January.
- %b: abbreviated month name, such as Jan.
- %B: full month name, such as January.
- %d: day of the month as a two-digit number with leading zero, such as 01, 02, ...,
31.
- %e: day of the month as a number, without leading zero, such as 1, 2, ..., 31.
- %A: full day name, such as Sunday.
- %a: abbreviated day name, such as Sun.
- %H: 24-hour clock hour as a two-digit number with leading zero, such as 00, 01, ...,
23.
- %I: 12-hour clock hour as a two-digit number with leading zero, such as 01, 02, ...,
12.
- %M: minute as a two-digit number with leading zero, such as 00, 01, ..., 59.
- %S: second as a two-digit number with leading zero, such as 00, 01, ..., 59.
- %p: AM or PM.
- %D: shortcut for the date using %m/%d/%y format.
- %F: shortcut for the date using %Y-%m-%d format.
- %T: shortcut for the time using %H:%M:%S format.
- %Z: timezone name, such as EDT.
Date and Time Function Categories
PilotScript includes numerous date/time functions, categorized as follows:
- Functions that create time and date values
- Functions that use fields to define dates and times
- Functions that change date and time values
- Date and time utilities
- Locale functions
Functions That Create Time and Date Values
-
If you do not specify the time-zone in the string, these functions use the UTC
time-zone.
The time fields for hours, minutes, seconds, and milliseconds are left undefined. If
you request an operation that requires definitions for all fields, they are
automatically filled with values from Julian date zero: January 1, -4713 BCE,
12:00:00.000 UTC.
-
If you do not provide a format, and the date is ambiguous (for example, 12/6/07), it
defaults to the order: month, day, and year (that is, date is December 6, 2007).
The exception is with European-style dates using the period separator (for example,
12.06.07), which are interpreted as day, month, and year (so the date is June 12,
2007).
-
You can perform mathematical operations such as addition, subtraction, or comparison
with date/time values. In these operations, the unit is always in days, and the
underlying math uses a calendar notation that represents the date by one number.
| Date and Time Function Name/Prototype |
Description |
Examples |
|
Date
Date Date(String date|Date dtv|Number julian [, String format])
|
Creates and returns a date/time value with a default format appropriate for a
date.
If you provide a single argument, it is handled as a date/time string in some
format (for example, "Oct 12, 1492"), a native date/time value or numeric Julian
date.
If you provide the date as a string, a date/time value is built from its
interpretation of that string.
If you provide two arguments, the second argument is the format string describing
the format of the date string, using syntax derived from strftime notation. This
removes ambiguity in the interpretation of date/time values. For more syntax
details, see DateSetFormat.
|
MyBirthday := Date('July 23, 1957');
Creates a property MyBirthday that contains "July 23, 1957".
MyBirthday := Date('23.07.1957','%d.%m.%Y');
Creates a property MyBirthday that contains "July 23,
1957", from a European-format date string. (The format string is not
truly required in this case, as the format is probably correctly calculated.)
TheDayAfter := Date(MyBirthday+1);
Creates a property TheDayAfter, which is the day after
"MyBirthday". (Note how simple math can be performed on dates,
as they are easily transformed into numbers that represent the number of days
since an exact past date.)
NumDaysOld := DateCurrent() - MyBirthday;
Creates a property NumDaysOld which is the number of days since
"MyBirthday".
IF (MyBirthday > DateCurrent() )
THEN
Error("You haven't been born yet!");
END IF;
Shows how date/time values are compared. You can compare them using equality,
inequality, and relational operators.
DateZero := Date(0.0);
Creates a date/time value using a Julian date, in this case, date zero:
January 1,-4713 BCE, 12:00:00.000 UTC.
|
|
DateCurrent
Date DateCurrent()
|
Creates and returns a date/time value using the current date/time and the local
time-zone. (The date/time fields of hours, minutes, seconds, and milliseconds are
defined, but the format is set so that only the day of month, month, and year are
displayed in the text string.) |
Now := DateCurrent();
Creates a property Now containing the current date (formatted
as, for example , "Jul 2, 2012").
|
|
DateFromYMD
Date DateFromYMD(Number year, Number month, Number day)
|
Creates and returns a date/time value by explicitly giving the year, month, and
day of month. |
MyBirthday := DateFromYMD(1987, 7, 23);
Creates a property MyBirthday that contains "July 23,
1987".
|
|
DateProposeFormat
String DateProposeFormat(String date)
|
Creates and returns a string representing the date format of the given string.
Use this with DateSetFormat(date, format) to set a format for
another date value. |
format := DateProposeFormat('February 29, 2004');
date := Date('25 Dec 2006')
DateSetFormat(date, format);
DateString := DateText(date);
DateString contains the string "December 25,
2006".
|
|
DateTime
Date DateTime(String datetime|Date dtv|Number julian [, String format])
|
Creates and returns a date/time value with a default format appropriate for a
date and time.
If you provide a single argument, it is handled as a date/time string in some
format (for example, Oct 12, 1492 11:00 AM), a native date/time
value, or a numeric Julian date. If you provide the date as a string, a date/time
value is built from its interpretation of that string.
If you provide two arguments, the second argument is the format string describing
the format of the date/time string, using syntax derived from strftime notation.
This removes ambiguity in the interpretation of date/time values. For more syntax
details, see DateSetFormat.
|
MyBirthday := DateTime('July 23, 1957 16:20:00');
Creates a property MyBirthday that contains "July 23, 1957 16:20:00".
IF (MyBirthday > CurrentDateAndTime)
THEN Error("You haven't been born yet!")
END IF;
Date/time values can be compared using equality, inequality, and relational
operators.
|
|
DateTimeCurrent
Date DateTimeCurrent()
|
Creates and returns a date/time value using the current date/time and local
time-zone. The date/time fields year, month, day of month, hours, minutes, and
seconds are displayed in the text string. |
Now := DateTimeCurrent();
Creates a property Now that contains the current date and time,
for example, "Jul 2, 2006 11:21:03".
|
|
DateTimeFromYMDHMS
Date DateTimeFromYMDHMS(Number year, Number month, Number day, Number hour, Number min, Number sec [, Number ms])
|
Creates and returns a date/time value by explicitly giving the year, month, day
of month, hour, minute, and second (and optionally milliseconds). |
MyBirthday := DateTimeFromYMDHMS(1987, 7, 23, 16, 20, 0);
Creates a property MyBirthday that contains "July 23,
1987, 4:20:00 PM".
|
|
Time
Date Time(String time|Date dtv|Number julian [, String format])
|
Creates and returns a date/time value with a default format appropriate for a
time.
If you provide a single argument, it is handled as a time string in some format
(for example, 13:22:33), a native date/time value, or a numeric Julian date. If
you provide the date as a string, a date/time value is built from its
interpretation of that string.
If you provide two arguments, the second argument is the format string describing
the format of the date/time value string, using syntax derived from strftime
notation. This removes ambiguity in the interpretation of date/time values. For
more syntax details, see DateSetFormat.
|
MyLunch := Time('12:30:00');
Creates a property MyLunch containing 12:30:00 PM.
LunchTomorrow := Time(MyLunch+1);
Creates a property LunchTomorrow which is the day after today's
lunch. Remember, addition to a date or time value is always in days.
IF (CurrentTime > MyLunch)
THEN Error("Late for lunch!");
END IF;
Date/time values are compared using equality, inequality, and relational
operators.
ExperimentDuration:= Time('10:55.500');
You can represent milliseconds by appending a period and a three-digit number. In
this case, the duration of the experiment was 10 minutes, 55 seconds, and 500
milliseconds.
|
|
TimeCurrent
Date TimeCurrent()
|
Creates and returns a date/time value using the current date/time and the local
time-zone. (The time fields o f year, month, and day of month are defined, but the
format is set so that only the hour, minute, and second are displayed in the text
string.) |
Now := TimeCurrent();
Creates a property Now containing the current time, for example,
"11:21:03".
|
|
TimeFromHMS
Date TimeFromHMS(Number hour, Number minute, Number sec [, Number ms])
|
Creates and returns a date/time value by explicitly giving the hour, minute,
and second (and optionally milliseconds). The format string is appropriate for a
time. |
MyLunch := TimeFromHMS(12, 30, 0);
Creates a property MyLunch that contains "12:30:00
PM". (The actual output format depends on what is appropriate for your
locale.)
|
Functions That Use Fields to Define Dates and Times
Use the functions below to access the fields that define date and time values in
PilotScript. You can also access several derived properties such as the day of the week.
| Date and Time Function Name/Prototype |
Description |
Example |
|
DateDayOfMonth
Number DateDayOfMonth(Date date)
|
Returns the day of the month contained in the given date as a number in the
range 1-31. If the day of the month is undefined, the function returns 1. |
CurrentDate := DateCurrent();
Day := DateDayOfMonth(CurrentDate);
Day contains a number representing the current day, (for
example, 16).
|
|
DateDayOfWeek
Number DateDayOfWeek([Date date])
|
Returns the day of the week for the given date as a number in the range 1-7,
with 1 as Monday. If the date is undefined, the function returns 1. Without a date
argument, the function returns the current date. |
CurrentDate := DateCurrent();
DOW := DateDayOfWeek(CurrentDate);
DOW contains a number representing the current day, (for
example, 4 for Thursday).
|
|
DateDayOfWeekText
String DateDayOfWeekText([Date date [, Boolean abbrev [, Boolean localize]]])
|
Returns the day of the week for the given date as text, (for example, Monday).
An optional second argument indicates if the result is an abbreviation of the
weekday name or the full weekday name. The default is False (not abbreviated). An
optional third argument indicates if the result is localized text or English. The
default is True (localized). If the date is undefined, the function returns an empty
string. Without a date argument, the function returns the current date. |
CurrentDate := DateCurrent();
DOW := DateDayOfWeek(CurrentDate);
DOW contains text representing the current day (for example
Thursday).
CurrentDate := DateCurrent();
DOWAbbrev := DateDayOfWeek(CurrentDate, True, False);
DOWAbbrev contains text representing the current day (for
example, Thu).
|
|
DateDayOfYear
Number DateDayOfYear([Date date])
|
Returns the day of the year for the given date as a number in the range 1-366.
If the date is undefined, the function returns 1. Without a date argument, the
function returns the current date. |
CurrentDate := DateCurrent();
DOY := DateDayOfYear(CurrentDate);
DOY contains a number representing the current day (for example,
75 for March 16).
|
|
DateFormat
String DateFormat(Date date)
|
Returns the format string to interpret the date string or create the output date
string. This format string uses a syntax derived from the standard function
strftime. For more syntax details, see DateSetFormat.
You have flexibility when creating date/time values from strings. For example, a
bike performance-monitoring program creates the following filename string:
"UserDefault_10_14_2005_19_11_19.csv". If you create a
date/time value from this string, use DateFormat to see how it
was interpreted. In this case, the format string is
"UserDefault_%m_%d_%Y_%H_%M_%S.csv". The date and time
information is correctly extracted.
|
D := DateTime('16 March, 2006 2:47:01');
F := DateFormat(D);
When creating a date/time value using the string "16 March, 2006
2:47:01", a format is automatically generated for it. The format using
DateFormat. F contains "%d %B, %Y
%H:%M:%S".
|
|
DateHour
Number DateHour(Date date)
|
Returns the hours contained in the given date as a number in the range 0-23. If
the hours are not defined, the function returns noon (12). |
CurrentDate := DateTimeCurrent();
H := DateHour(CurrentDate);
H contains a number representing the current hour (for example,
12).
|
|
DateJulian
Number DateJulian([Date date])
|
Returns the current date and time as a Julian date, represented as a
floating-point number. (You get the same value if you coerce a date/time value into
a double value using ChangePropertyType(val,
'SciTegic.value.DoubleValue').) The function returns any undefined fields
as Julian date zero, without changing the underlying date/time value. To convert a
Julian date into a Gregorian date, use the U.S. Naval Observatory's Julian Date
converter - https://www.onlineconversion.com/julian_date.htm. In PilotScript, create a
date, set its value from a Julian date using the DateSetJulian
function, then find its string representation using
DateText. |
D := DateTime('16 March, 2006 2:47:01');
J := DateJulian(D);
J contains the number "2453810.6159838".
To calculate the number of days between two Julian dates, subtract one number
from the other. To calculate the number of hours between the two dates, subtract
one number from the other and multiply the result by 24. The Julian date is always
relative to Coordinated Universal Time (UTC, same time-zone offset as GMT). So the
same date and time in different time-zones returns a different Julian date. The
time-zone of the date/time value will not be changed.
|
|
DateMilliseconds
Number DateMilliseconds(Date date)
|
Returns the number of milliseconds contained in the given date/time as a number
in the range 0-999. If the milliseconds are not defined, the function returns
0. |
D := Time('11:10.333');
MS := DateMilliseconds(D);
MS contains the number 333.
|
|
DateMinute
Number DateMinute(Date date)
|
Returns the minutes contained in the given date as a number in the range 0-59.
If the minutes are not defined, the function returns 0. |
CurrentDate := DateTimeCurrent();
Minute := DateMinute(CurrentDate);
Minute contains a number representing the current minutes (for
example, 24).
|
|
DateMonth
Number DateMonth(Date date)
|
Returns the month contained in the given date as a number in the range 1-12. If
the month is not defined, the function returns 1. |
CurrentDate := DateCurrent();
Month := DateMonth(CurrentDate);
Month contains a number representing the current month (for
example, 3 for March).
|
|
DateMonthText
String DateMonthText(Date date[, Boolean abbrev [, Boolean localize]])
|
Returns the month contained in the given date as a text string. If the source
date string does not contain a month, the function returns an empty string. An
optional second argument indicates if the result is an abbreviation of the month
name or the full month name. The default is False (not abbreviated). An optional
third argument indicates if the result in localized text or in English. The default
is True (localized). |
CurrentDate := DateCurrent();
Month := DateMonthText(CurrentDate);
Month contains text representing the current month (for example,
March).
CurrentDate := DateCurrent();
MonthAbbrev := DateMonthText(CurrentDate, True);
MonthAbbrev contains text representing the current month (for
example, Mar).
|
|
DateSecond
Number DateSecond(Date date)
|
Returns the seconds contained in the given date as a number in the range 0-59.
If the seconds are not defined, the function returns 0. |
CurrentDate := DateTimeCurrent();
Seconds := DateSecond(CurrentDate);
Seconds contains a number representing the current seconds (for
example, 33).
|
|
DateSecondsSince1970
Number DateSecondsSince1970([Date date])
|
Returns the number of seconds from midnight on January 1, 1970 in UTC
time-zone, to given date, (similar to "time_t"). If the date is before 1 January,
1970, the function returns -1. Without the date argument, the function uses the
current date. After Tuesday, January 19, 2038 03:14:07 UTC, this number will exceed
the limit of a signed 32-bit integer. |
D := DateTime('16 March, 2006 2:47:01');
SS1970 := DateSecondsSince1970(D);
SS1970 contains the number "1142477221".
|
|
DateText
String DateText(Date date)
|
Returns a text representation of the current date. For dates created from
strings, typically the same string results. Otherwise, the format string is used to
construct the string from the date information. (You get the same value if you
coerce a date/time value into a string value using ChangePropertyType(val,
'SciTegic.value.StringValue').) |
D := DateTimeCurrent();
DS := DateText(D);
DS contains a text string representing the current date (for
example, Thu Mar 16 15:04:48 2006).
|
|
DateTimeZone
String DateTimeZone([Date date])
|
Returns the time-zone string used by the given date. Without the date argument,
the function returns the local time-zone. |
D := DateTime('July 10, 2006 11:10:00 EDT');
TZ := DateTimeZone(D);
TZ contains the string "EDT".
|
|
DateYear
Number DateYear(Date date)
|
Returns the year contained in the given date. If the year is undefined, the
function returns -4713 (year of Julian date zero). |
CurrentDate := DateCurrent();
Year := DateYear(CurrentDate);
Year contains a number representing the current year (for
example 2006).
|
Functions That Change Date and Time Values
Use the following function to make changes to date/time values in PilotScript:
Note:
For all DateAddX functions, the time and time-zone may be
automatically changed to reflect whether standard or daylight saving time is appropriate
if the time-zone is in a region that performs daylight saving time.
| Date and Time Function Name/Prototype |
Description |
Example |
|
DateAddDays
None DateAddDays(Date date, Number days)
|
Adds days to the given date. If the number of days is negative, the function
subtracts them from the date. (You can also use numeric addition directly to add
and subtract days from a date/time value; if "D" is a date, then
"D+7" is the date plus seven days.).
If the time-zone is in a region that advances an hour during daylight saving
time, the time and time-zone might be automatically changed to reflect whether
standard or daylight saving time is appropriate.
|
D := DateTime('16 March, 2006 2:47:01');
DateAddDays(D, 4);
S := DateText(D);
S contains "20 March, 2006 02:47:01".
|
|
DateAddHours
None DateAddHours(Date date, Number hours)
|
Adds hours to the given date. If the number of hours is negative, the function
subtracts them from the date.
If the time-zone is in a region that advances an hour during daylight saving
time, the time and time-zone might be automatically changed to reflect whether
standard or daylight saving time is appropriate.
|
D := DateTime('16 March, 2006 2:47:01');
DateAddHours(D, 4);
S := DateText(D);
S contains "16 March, 2006 06:47:01".
|
|
DateAddMilliseconds
None DateAddMilliseconds(Date date, Number milliseconds)
|
Adds milliseconds to the given date. If the given number of milliseconds is
negative, the function subtracts them from the date.
If time-zone is in a region that advances an hour during daylight saving time,
the time and time-zone might be automatically changed to reflect whether standard
or daylight saving time is appropriate.
|
D := DateTime('16 March, 2006 2:47:01.333');
DateAddMilliseconds(D, 111);
S := DateText(D);
S contains "16 March, 2006 02:47:01.444".
|
|
DateAddMinutes
None DateAddMinutes(Date date, Number minutes)
|
Adds minutes to the given date. If the number of minutes is negative, the
function subtracts them from the date.
If the time-zone is in a region that advances an hour during daylight saving
time, the time and time-zone might be automatically changed to reflect whether
standard or daylight saving time is appropriate.
|
D := DateTime('16 March, 2006 2:47:01');
DateAddMinutes(D, 4);
S := DateText(D);
S contains "16 March, 2006 02:51:01".
|
|
DateAddMonths
None DateAddMonths(Date date, Number months)
|
Adds months to the given date. If the number of months is negative, the function
subtracts them from the date. The day of month will be reduced to the closest
valid day if it exceeds the maximum days in the resulting month (see example).
If the time-zone is in a region that advances an hour during daylight saving
time, the time and time-zone might be automatically changed to reflect whether
standard or daylight saving time is appropriate.
|
D := DateTime('16 March, 2006 2:47:01');
DateAddMonths(D, 4);
S := DateText(D);
S contains "16 July, 2006 02:47:01".
D2 := Date('31 March, 2008');
DateAddMonths(D2, -1);
S2 := DateText(D2);
S2 contains "29 February, 2008".
|
|
DateAddSeconds
None DateAddSeconds(Date date, Number seconds)
|
Adds seconds to the given date. If the number of seconds is negative, the
function subtracts them from the date.
If the time-zone is in a region that advances an hour during daylight saving
time, the time and time-zone might be automatically changed to reflect whether
standard or daylight saving time is appropriate.
|
D := DateTime('16 March, 2006 2:47:01');
DateAddSeconds(D, 4);
S := DateText(D);
S contains "16 March, 2006 02:47:05".
|
|
DateAddYears
None DateAddYears(Date date, Number years)
|
Adds the given number of years to the given date. If the number of years is
negative, the function subtracts them from the date. The day of month is reduced
to the closest valid day if it exceeds the maximum days in the resulting
month.
If the time-zone is in a region that advances an hour during daylight saving
time, the time and time-zone might be automatically changed to reflect whether
standard or daylight saving time is appropriate.
|
D := DateTime('16 March, 2006 2:47:01');
DateAddYears(D, 4);
S := DateText(D);
S contains "16 March, 2010 02:47:01".
D2 := Date('29 February, 2008');
DateAddYears(D2, -7);
S2 := DateText(D2);
S contains "28 February, 2001".
|
|
DateChangeTimeZone
None DateChangeTimeZone(Date date, String tzstring)
|
Changes the time-zone of the given date, incrementing or decrementing the time as
required. (To change the time zone without changing the remainder of the time, use
DateSetTimeZone.)
If the time-zone is in a region that advances an hour during daylight saving
time, the time and time-zone might be automatically changed to reflect whether
standard or daylight saving time is appropriate.
|
D := DateTime('12 July 2006 12:00:00 EDT');
DateChangeTimeZone(D, 'UTC');
Text := DateText(D);
Text contains "12 July 2006 19:00:00 UTC", showing both the
changed time-zone and the shift in hours to move from EDT to UTC.
|
|
DateSetDayOfMonth
None DateSetDayOfMonth(Date date, Number dayofmonth)
|
Sets the day of the month in the given date, giving a number between 1 and the
end of the month. |
D := DateTime('16 March, 2006 2:47:01');
DateSetDayOfMonth(D, 4);
S := DateText(D);
S contains "4 March, 2006 02:47:01".
|
|
DateSetFormat
None DateSetFormat(Date date, String format)
|
Sets the format string used to output the date, using syntax derived from
strftime notation. Differences from strftime notation include:
%s (lowercase 's') is replaced by the millisecond as a decimal
number [000,999].
%U and %W (variations for "week number of the
year") are not supported.
Modified Conversion Specifiers (%E and %O) are
ignored.
|
D := Date('16 March 2006');
DateSetFormat(D, '%m/%d/%y');
S := DateText(D);
S contains the string "03/16/06".
CurrentTime := TimeCurrent();
DateSetFormat(CurrentTime, '%m/%d/%y %H:%M:%S');
S := DateText(D);
S contains the current time, for example "**/**/**
12:32:48".
PilotScript date/time values have the concept of undefined fields. If you attempt
to print out an undefined field in your format, it appears as a sequence of
asterisks (****). See DateFieldIsDefined and DateFillUndefined for options regarding
undefined fields
|
|
DateSetHour
None DateSetHour(Date date, Number hour)
|
Sets the hour in the given date, giving a number between 0 and 23. |
D := DateTime('16 March, 2006 2:47:01');
DateSetHour(D, 4);
S := DateText(D);
S contains "16 March, 2006 04:47:01".
|
|
DateSetJulian
None DateSetJulian(Date date, Number julian)
|
Defines a date/time value from a Julian date (a calendar notation in which the
date is represented by one number). The time-zone will not be changed, so the
defined date and time will reflect the time-zone of the date/time value. |
D := DateTimeCurrent();
DateSetJulian(D, 2453810.6159838);
S1 := DateText(D);
The first line creates a date/time value D in the current
time-zone for later use. S1 contains a text string,
"03/15/06 19:47:01" when the current time-zone is Pacific
Daylight Time.
D := DateTime('');
DateSetJulian(D, 2453810.6159838);
S2 := DateText(D);
Next, D is created with all fields undefined.
S2 contains the string, "03/16/06 02:47:01" in
UTC time-zone.
|
|
DateSetMilliseconds
None DateSetMilliseconds(Date date, Number milliseconds)
|
Sets the milliseconds in the date, giving a number between 0 and 999 |
D := DateTime('16 March, 2006 2:47:01.000');
DateSetMilliseconds(D, 333);
S := DateText(D);
S contains "16 March, 2006 02:47:01.333".
|
|
DateSetMinute
None DateSetMinute(Date date, Number minute)
|
Sets the minute in the date, giving a number between 0 and 59. |
D := DateTime('16 March, 2006 2:47:01');
DateSetMinute(D, 4);
S := DateText(D);
S contains "16 March, 2006 02:04:01".
|
|
DateSetMonth
None DateSetMonth(Date date, Number month)
|
Sets the month in the date, giving a number between 1 and 12. |
D := DateTime('16 March, 2006 2:47:01');
DateSetMonth(D, 4);
S := DateText(D);
S contains "16 April, 2006 02:47:01".
|
|
DateSetSecond
None DateSetSecond(Date date, Number seconds)
|
Sets the seconds in the date, giving a number between 0 and 59. |
D := DateTime('16 March, 2006 2:47:01');
DateSetSecond(D, 4);
S := DateText(D);
S contains "16 March, 2006 02:47:04".
|
|
DateSetSecondsSince1970
None DateSetSecondsSince1970(Date date, Number
secondsSince1970)
|
Defines all the fields in a date/time value (year, month, day, hour, minute,
and second) from the number of seconds (must be positive) since midnight on January
1, 1970 in UTC time-zone. (This is similar to the "time_t" value
available on many computer systems.) The time-zone will not be changed, so the
defined date and time will reflect the time-zone of the date/time value. Note that
after Tuesday, January 19, 2038 03:14:07 UTC, this number will exceed the limit of a
signed 32-bit integer. |
D := DateTimeCurrent();
DateSetSecondsSince1970(D, 12345678);
S1 := DateText(D);
The first line creates a date/time value D in the current
time-zone for later use. S1 contains "Sat May 23 14:21:18
1970" when current time-zone is Pacific Daylight Time.
D := DateTime('');
DateSetSecondsSince1970(D, 12345678);
S2 := DateText(D);
The first line creates a date/time value D with all fields
undefined. S2 contains "Sat May 23 21:21:18
1970" in UTC time-zone.
|
|
DateSetText
None DateSetText(Date date, String string [, String format])
|
Defines a date/time value from a string and optional format. With two
arguments, handles it as a date/time string in some format, and builds a date/time
value from its interpretation of the string. A third argument is supported, which is
the format string describing the format of the date/time value string, using syntax
derived from strftime notation. This removes ambiguity in the interpretation of
date/time values. For more syntax details, see DateSetFormat. |
DateSetText(D, '16 March 2006');
Assigns the date/time property D to the date 16 March
2006.
|
|
DateSetTimeZone
None DateSetTimeZone(Date date, String tzstring)
|
Sets the time zone of the date without altering the time or date in any other
way. (To change the time zone with the appropriate shift in hours, use
DateChangeTimeZone.)
The time-zone will NOT be automatically changed to reflect whether standard or
daylight saving time is appropriate.
|
D := DateTime('16 March, 2006 2:47:01');
DateSetTimeZone(D, 'PDT');
Offset := DateLocalToGMT(D);
Offset contains the number "7", as UTC (same time-zone as GMT)
is 7 hours ahead of Pacific Daylight Time.
|
|
DateSetYear
None DateSetYear(Date date, Number year)
|
Sets the year in the given date. |
D := DateTime('16 March, 2006 2:47:01');
DateSetYear(D, 1999);
S := DateText(D);
S contains "16 March, 1999 02:47:01".
|
Date and Time Utilities
The following functions are useful date and time utilities for PilotScript:
| Date and Time Function Name/Prototype |
Description |
Example |
|
DateDaysBetween
Number DateDaysBetween(Date date1, Date date2)
|
Returns the number of days between the two dates, ignoring any associated times
or time-zones (for example, if "date1" is one minute before
midnight, and "date2" is one minute after midnight, they have one
day between them.) Two dates on the same day return zero, whatever the times or
time-zones.
This function returns a negative number of days if "date2" is
later than "date1" (think of it as "date1" -
"date2"). You can also use Julian date to perform precise
date/time mathematics containing both date and time components.
|
DB := DateDaysBetween('July 23, 1957','1 January, 2006');
DB contains "-17694".
D1 := DateTime('22:30 PST', '%H:%M %Z');
D2 := D1;
DateChangeTimeZone(D2, 'EST');
DB2 := DateDaysBetween(DB2, DB1);
DB2 contains "1".
|
|
DateDaysInMonth
Number DateDaysInMonth(Date date)
|
Returns the number of days in the month of the given date. (Correctly accounts
for leap years.) |
D := Date('16 March, 2006 2:47:01');
DIM := DateDaysInMonth(D);
DIM contains "31".
|
|
DateFieldIsDefined
Boolean DateFieldIsDefined(Date date, Number fieldIndex)
|
Returns True (if the given field is defined), else False. Undefined fields are
usually invisible and default to defined values (if required) to perform operations
such as sorting. The allowable field index values include: Year
(1), Month (2), Day of the month (3),
Hour (4), Minute (5), Second
(6), Millisecond (7). |
T := Time('12:22:33');
IsDef := DateFieldIsDefined(T, 3);
IsDef contains "False".
|
|
DateFillUndefined
None DateFillUndefined(Date date, [Boolean flagForCurrentDate])
|
Fills any undefined date/time fields. If the flag for current date is false or
not provided, the undefined fields are filled using 1 January, -4713 BCE,
12:00:00.000. Otherwise, the undefined fields are filled using the current date and
the time of 12:00:00.000. |
T := Time('12:22:33');
DateFillUndefined(T, true);
DateSetFormat(T, '%Y/%m/%d %H:%M');
S := DateText(T);
S contains a string representing current date (for example,
"2006/03/21 12:22").
|
|
DateIsDST
Boolean DateIsDST(Date date)
|
Returns True (if the date is in a period of Daylight Savings Time), false
otherwise. |
D := Date('1 March, 2006 2:47:01');
YES := DateIsDST(D);
YES contains "False".
|
|
DateIsLeapYear
Boolean DateIsLeapYear(Date date)
|
Returns True if the year in the date is a leap year, false otherwise. |
D := Date('16 March, 2006 2:47:01');
YES := DateIsLeapYear(D);
YES contains "False".
|
|
DateLocalToGMT
Number DateLocalToGMT([Date Date])
|
If no argument is given, returns the number of hours required to translate
local time (as set by your operating system) to Greenwich Mean Time (GMT), also
known as UTC (Coordinated Universal Time). If an argument is given, returns the
number of hours required to translate the given date, in the given time-zone, to
GMT. |
Offset := DateLocalToGMT();
In San Diego, California, during standard time, Offset contains
"8".
D := Date('1 January, 2006 2:47:01 PST');
PSTOffset := DateLocalToGMT(D);
DateChangeTimeZone(D, 'EST');
ESTOffset := DateLocalToGMT(D);
PSTOffset contains "8", and
ESTOffset contains "5".
|
|
DateSetFieldUndefined
None DateSetFieldUndefined(Date Date, Number fieldIndex)
|
Makes the given field undefined. For definitions of the field indices, see
DateFieldIsDefined. |
T := Time('12:22:33');
DateSetFieldUndefined(T, 5);
Text := DateText(T);
Text contains "12:**:33".
The undefined field displays two asterisks.
|
|
DateWeekOfYear
Number DateWeekOfYear(Date date)
|
Returns the index of the week in the year, using the ISO 8601 standard, where
weeks begin with a Monday, and the first week of the year is the first week that
includes a Thursday. Thus, January 1 returns "52" when it is
included in the previous year. Use this function to determine the week where this
standard would place a given day. |
D := Date('16 March, 2006 2:47:01');
WOY := DateWeekOfYear(D);
WOY contains "11".
|
|
DateWeekOfYearYear
Number DateWeekOfYearYear(Date date)
|
Returns the year in which the ISO 8601 standard would place a given date using
the week of the year result from DateWeekOfYear. For example,
January 1, 2006, is contained in the last week of 2005. |
D := Date('1 January, 2006 2:47:01');
WOYY := DateWeekOfYearYear(D);
WOYY contains "2005".
|
Locale Functions
The following functions are useful for setting locales with PilotScript:
| Date and Time Function Name/Prototype |
Description |
Example |
|
DateLocale
String DateLocale()
|
Returns the current locale string. If you have never set the locale, this is
typically the "C" locale, determined by the local computer. (The
computer "locale" is not returned by this call, but the locale as reflected by the
date/time subsystem.) |
Locale := DateLocale();
Locale contains the text "C", unless you made a
previous call to DateSetLocale.
|
|
DateSetLocale
None DateSetLocale(String localeName)
|
Sets the default locale for the output format of time strings. This might change
the language of the month text, the month abbreviations, the weekday text, the
weekday abbreviation, and the AM/PM designator. Also, date/time values created
after this call might have their default format strings changed to reflect the
preferences of the requested locale.
The actual computer locale is not permanently changed by this call. The date/time
subsystem temporarily changes the locale and saves the appropriate text strings,
then returns the computer to its native state. This reduces the risk of negatively
affecting other programs running concurrently.
|
D := Date('Wednesday, June 7, 2006');
DateSetLocale('German');
Text := DateText(D);
Text contains "Mittwoch, Juni 07, 2006".
|
|