Date Syntax

Date functions have the following syntax (month specified as 1 - 12):



datetime d;
 
d = date(1995,4,6);
d = date(1995,4,6,12,0);
d = date("%y/%m/%d", "95/4/6");

The d = date("%y/%m/%d", "95/4/6"); format enables you to convert any string type into a datetime type by indicating a format mask ("%y/%m/%d") along with the string ("95/4/6") you want to convert. Use this function if you are using nonstandard syntax and must specify the syntax you are using.

Important: You must use the date format specified. Initializing a date using an assignment statement or date extend rule function with an incorrect date format, such as "", will force the translator to initialize the date to -1000 millisecond before 1970, 00:00:00 GMT. This could result in a problem with the date calculation. The Map Editor does validate dates and will not report an error on compile.

For more information about date syntax, see date.

For example, if you want to add five days to a date in a field, you must:

  1. Verify that you are using a standard rule that loads the current date into a field.

    For more information about loading a date into a field, see Using the System Variable Standard Rule.

  2. Use the following extended rule logic to add five days to the date in that field:
    
    #TheField = #TheField << days(5);
    //The field is called #TheField
    

<< Operator

You can use the << operator to modify your datetime variable by adding time increments. Valid modifiers are:

  • years
  • months
  • weeks
  • days
  • hours
  • minutes
  • seconds

For example:


datetime d;
d=#Date_Field <<weeks(2);
//This adds 2 weeks to the date in the date field named Date_Field

Time Syntax

Time functions have the following syntax:


d = time(12,0);
d = time(12,0,59);

You can use the << operator to modify your datetime variable by adding time increments (seconds, minutes, years). For example:


datetime d;
d=#Time_Field <<seconds(1);
//This adds 1 second to the time field named Time_Field

get and set Syntax

The get and set functions enable you to access (get) or modify (set) individual components of a datetime type. For more information about the get and set functions, see get and set.

Here is the syntax to use:



integer a;
datetime d;
a = get days (d);
a = get hours (d);
set hours(d,a);
set days (d,a);