Date and Strdate Functions
Date and Strdate Functions
White Paper
Date/time manipulation using the
DATE and STRDATE functions
The information contained in this document represents the current view of Sterling Commerce on the issue discussed as of the date
of publication. Because Sterling Commerce must respond to changing market conditions, it should not be interpreted to be a
commitment on the part of Sterling Commerce, and Sterling Commerce cannot guarantee the accuracy of any information presented
after the date of publication.
This document is for informational purposes only. STERLING COMMERCE MAKES NO WARRANTIES, EXPRESSED OR
IMPLIED, IN THIS DOCUMENT.
2007 Sterling Commerce. All rights reserved.
Page 1 of 8
<Common Mapper>
TABLE OF CONTENTS
PURPOSE......................................................................................................................................................................3
BACKGROUND...........................................................................................................................................................3
STRDATE......................................................................................................................................................................4
SYNTAX:.....................................................................................................................................................................4
DATE:............................................................................................................................................................................5
SYNTAX:.....................................................................................................................................................................5
FORMAT SPECIFIERS...............................................................................................................................................6
ADDING OR SUBTRACTING FROM DATE/TIME VALUES..............................................................................7
OBTAINING THE CURRENT DATE/TIME THROUGH EXTENDED RULE...................................................8
Page 2 of 8
<Common Mapper>
Purpose
The purpose of this paper is to introduce the use of the extended rule syntax for
converting Date/Time formatted fields to strings (STRDATE) and string formatted fields
to dates and time (DATE). Other topics which will be covered in this paper are the
parameters used in the syntax to convert from one format to the other and how to add
and subtract from Date/Time formatted fields.
Background
The reason this paper is written is to give the user a starting point to add
extended rule functionality to a map.
Page 3 of 8
<Common Mapper>
STRDATE
The STRDATE function converts a datetime type into a string using a format that you
specify. This function allows you to include static characters such as a slash (/), which
gives you access to full date support.
The STRDATE function can be used to:
Convert a date/time value to a string to update it to a string column in a database
table
Convert a date/time value to a string to display the value in a messagebox
Syntax:
STRDATE (datetime,"format", string);
where: datetime
= datetime variable/field
format
= date format
string
= string variable/field
Example 1:
//Convert a Date field (#Date_Field) to a string value to populate the Ref Data column.
STRDATE (#Date_Field,"%y/%m/%d",#String_Field);
UPDATE DOCUMENT SET REFERENCEDATA = #String_Field;
Example 2:
//Convert a Date field (#Date_Field) to a string value to populate the Document
Name //column.
STRDATE (#Date_Field,"%y/%m/%d",#String_Field);
UPDATE PROCESSDATA SET XPATHRESULT = #String_Field WHERE XPATH =
PO_DATE;
Example 3:
//Convert a Date field (#Date_Field) to a string value to use in a Messagebox
extended //rule.
STRING [100] msg;
STRDATE (#Date_Field,"%y/%m/%d",#String_Field);
msg = PO DATE: + #String_Field;
MESSAGEBOX(msg,0);
Page 4 of 8
<Common Mapper>
DATE:
The DATE format enables you to convert any string format type into a datetime format
type by indicating a format mask ("%y/%m/%d") along with the string ("2007/04/06") you
want to convert.
The DATE function can be used to:
Convert a string value into a date/time value (Syntax 1)
Hardcode a date/time value into a variable or field (Syntax 2)
Syntax 1:
DATETIME = DATE("format", string);
where: datetime
=
datetime variable
format
=
date format
string
=
string variable
Example:
//Hard code the value contained in a string field (#string_date) into the date variable d
DATETIME d;
d = DATE(0,0,0); //initialize the date variable
d = DATE("%Y/%m/%d", #string_date);
Syntax 2:
DATETIME = DATE(Number);
where: Number
=
The order of the numbers will need to match the Format specified in the Validation area
of the #Date_field the hard coded value is to be stored in. The value for Year has to be 4
characters long. The value for the month is the number 1-12, and the day is a number
1-31.
Example 1:
//Hard code the date 20070406 into the date variable d and store it to #Date_field //
(YYYYMMDD)
DATETIME d;
d = DATE(0,0,0); //initialize the date variable
d = DATE(2007,4,6);
#Date_field = d;
Example 2:
//Hard code the date 20070406 with a time of 12:00 into the date variable d and store it
to //#Date_field (YYMMDDHHMM)
DATETIME d;
d = DATE(0,0,0,0,0); //initialize the date variable
d = DATE(2007,4,6,12,0);
#Date_field = d;
Page 5 of 8
<Common Mapper>
Format Specifiers
This table lists the format specifiers available for the DATE and STRDATE functions.
These specifiers are used with the two functions (DATE and STRDATE) to indicate what
format the converted date/time will be converted.
Please check the Help text in the version of Gentran you are using.
Format
Specifier
Description
%8
%a
%A
%b
%B
%d
%H
%I
%j
%m
%M
%S
%U
Week of the year as a decimal number, with Sunday as the first day of the week (00 51).
%w
%W
Week of the year as a decimal number, with Monday as the first day of the week (00
- 51).
%y
%Y
%%
Percent sign.
Page 6 of 8
<Common Mapper>
Page 7 of 8
<Common Mapper>
Page 8 of 8