Date/Time Manipulations

TRIMpl stores the date with timestamp by default. However, the TRIM default format mask is set to display only 'DD-MON-YY'. While functions such as prompt(mydate) or printf(mydate) print 'DD-MON-DD' on the screen, mydate actually stores 'DD-MON-YY HH:MI:SS'. This point is demonstrated in the following TRIMpl program.

Care must be taken to determine if the timestamp is needed or if it should be set to zero. For example, if the timestamp is stored in the database, then queries must include the exact date and timestamp to retrieve the record. If '08-DEC-97 10:26:08' is stored in a database field called mydate, then the select statement must also include the timestamp (Select mydate from mytable where mydate= '08-DEC-97 10:26:08'). The following select will fail (Select mydate from mytable where mydate= '08-DEC-97'). However, this select statement will work if the value of mydate in the database is '08-DEC-97 00:00:00'.

To set the timestamp to zero, use this assignment:
mydate= to_date(to_char(SYSDATE,"DD-MON-YY"));

{
/* datetime.pl:  An example of date manipulation. */
/* To compile: trimgen datetime.pl -a             */
/* To run:     trimrun datetime                   */
datetime mydate;

mydate= SYSDATE;
prompt("mydate with timestamp: "
      ^^to_char(mydate,"DD-MON-YY HH:MI:SS") );/* Prints: 08-DEC-97 10:26:08 */

mydate= to_date(to_char(SYSDATE,"DD-MON-YY") );
prompt("mydate with timestamp set to zero: "
       ^^to_char(mydate,"DD-MON-YY HH:MI:SS")); /* Prints: 08-DEC-97 00:00:00 */
}