copyright 2007, information builders. slide 1 what's new with dates renee teatro information...
TRANSCRIPT
Copyright 2007, Information Builders. Slide 1
What's New With Dates
Renee TeatroInformation Builders
FUN ConferenceOctober 2009
Copyright 2007, Information Builders. Slide 2
What's New With Dates OVERVIEW
Review Legacy vs. Smart Dates Dialogue Manager and Dates DATETIME Functions
What's New Functions
Displaying DatesDate Manipulation
Copyright 2007, Information Builders. Slide 3
What's New With Dates Review – Legacy Dates Vs. Smart Dates
Legacy Dates
Dates Physically Stored As A Recognizable Date
Determined By USAGE:
A8YYMD ('20090317') A6YMD ('090317')
I8YYMD (20090317) I6YMD (090317)
Copyright 2007, Information Builders. Slide 4
What's New With Dates Review – Legacy Dates Vs. Smart Dates
Legacy Dates
Considerations
CANNOT Do Date Arithmetic
Can Be Used To Specify Date Range Only If The Format is A8YYMD or I8YYMD
BEGDATE/I8YYMD=20090315;ENDDATE/I8YYMD=20090415;DIFFDAYS/I5=ENDDATE – BEGDATE;Result of DIFFDAYS: 100 DIFFDAYS=ENDDATE – BEGDATE; 20090415 - 20090315
OPENDATE has USAGE of A8MDYY and VALUE of '05312008'WHERE OPENDATE GE '01012009'
Will OPENDATE of 05312008 Show In The Output?YES – A String Starting With 05 Is Greater Than a String Starting with 01
Copyright 2007, Information Builders. Slide 5
What's New With Dates Review – Legacy Dates Vs. Smart Dates
Smart Dates
Dates Physically Stored As The OFFSET of Days From 1900/12/31
Determined By USAGE:
YYMD - 20090317
YYMD (39523) YMD (39523)
What Is Stored If The FORMAT is YMD and the VALUE is 090317?
How Does FOCUS Know If The Value Is 20090317 or 19090317?
DEFCENT and YRTHRESH: DEFCENT = 19 and YRTHRESH <= year use DEFCENT - 2998 DEFCENT = 19 and YRTHRESH > year use DEFCENT + 1 - 39523
Copyright 2007, Information Builders. Slide 6
What's New With Dates Review – Legacy Dates Vs. Smart Dates
Converting Dates With DEFINE or COMPUTE
Legacy to Smart: NEWDATE/MDYY=LEGACYDATE;
Smart to Legacy: NEWDATE/A8YMD=SMARTDATE;
Why Convert?
To Perform Date Arithmetic
To Screen Data Not in YYMD format
Copyright 2007, Information Builders. Slide 7
What's New With Dates Review – Dialogue Manager
There Are No Date Formats In Dialogue Manager
A Date Must Be Converted To A Smart Date Using The DATECVT Subroutine, Perform Calculation.If Necessary, Convert Back To A Legacy Date.
Copyright 2007, Information Builders. Slide 8
What's New With Dates Review – Dialog Manager
Example:Calculate the number of days from now until Halloween.
-SET &THISYEAR = EDIT(&YYMD,'9999');-SET &THISHALL = &THISYEAR | '1031';-* CONVERT DATES TO SMARTDATES-SET &STODAY = DATECVT(&YYMD,'I8YYMD','YYMD');-SET &SHALLOW = DATECVT(&THISHALL,'I8YYMD','YYMD');-* SUBTRACT THE 2 SMART DATES TO GET DIFFERENCE-SET &DAYSTOHALL = &SHALLOW - &STODAY;-TYPE DAYS TO HALLOWEEN: &DAYSTOHALL
Output of &ECHO=ALL:
1. -SET &THISYEAR = EDIT(20090419,'9999');
2. -SET &THISHALL = 2009 | '1031';
3. -* CONVERT DATES TO SMARTDATES
4. -SET &STODAY = DATECVT(20090419,'I8YYMD','YYMD');
5. -SET &SHALLOW = DATECVT(20091031,'I8YYMD','YYMD');
6. -* SUBTRACT THE 2 SMART DATES TO GET DIFFERENCE
7. -SET &DAYSTOHALL = 39751 - 39556;
8. -TYPE DAYS TO HALLOWEEN: 195
9. DAYS TO HALLOWEEN: 195
Copyright 2007, Information Builders. Slide 9
What's New With Dates Review – DATETIME formats
Dependent On The Adapter
FOCUS
FORMAT=H17 can store: YYYYMMDDHHMMSSsss(millisecond)
FORMAT=H20 can store: YYYYMMDDHHMMSSsssmmm(microsecond)
Copyright 2007, Information Builders. Slide 10
What's New With Dates Review – DATETIME formats
Oracle - TIMESTAMP
USAGE=HYYMDS, ACTUAL=HYYMDS stores: YYYYMMDDHHMMSS 2008/01/01 13:59:23
USAGE=HYYMDs, ACTUAL=HYYMDs stores: YYYYMMDDHHMMSSsss 2008/01/01 13:59:23.218
USAGE=HYYMDm, ACTUAL=HYYMDm stores: YYYYMMDDHHMMSSsssmmm 2008/01/01 13:59:23.218431
Copyright 2007, Information Builders. Slide 11
What's New With Dates Review – DATETIME formats
MS SQL Server
DATETIME USAGE=HYYMDs, ACTUAL=HYYMDs
stores: YYYYMMDDHHMMSSsss(milliseconds)range: 1/1/1753 to 12/31/9999
Why 1753?
Copyright 2007, Information Builders. Slide 12
What's New With Dates Review – DATETIME formats
DB2
TIMESTAMP USAGE=HYYMDm, ACTUAL=HYYMDm
stores: YYYYMMDDHHMMSSsssmmm(microseconds)
Copyright 2007, Information Builders. Slide 13
Format Display Storage
A6YMD 05/01/31 050131
A8YYMD 2005/01/31 20050131
I6YMD 05/01/31 Binary(50131)
P6YMD 05/01/31 Packed(50131)
I8YYMD 2005/01/31 Binary(20050131
P8YYMD 2005/01/31 Packed(2050131)
YMD 05/01/31 1492 or 38017 *
YYMD 2005/01/31 38017
HYYMDS 2005/01/31 05:4500 Binary
* SET YRTHRESH=50
What's New With Dates Review – Formats
Copyright 2007, Information Builders. Slide 14
DATECVT converts the format of a date in an application without requiring an intermediate calculation DATEADD function adds a unit to or subtracts a unit from a date format HDTTM function converts a date value to a date‑time field HPART function extracts a specified component from a date‑time value and returns it in numeric format
HINPUT function converts an alphanumeric string to a date‑time value.
HDIFF function calculates the number of units between two date-time values
What's New With Dates Review – Functions
Copyright 2007, Information Builders. Slide 15
DATECVT(date, 'infmt', 'outfmt'[, outfield]) Converts the format of a date in an application without requiring an intermediate calculationDATECVT(HIRE_DATE, 'I6YMD', 'YYMD') where: date - Is the date to be converted. If you supply an invalid date, DATECVT returns zero. When the conversion is performed, a legacy date obeys any DEFCENT and YRTHRESH parameter settings supplied for that field.
infmt - AlphanumericIs the format of the date enclosed in single quotation marks. It is one of the following:
A non-legacy date format (for example, YYMD, YQ, M, DMY, JUL). A legacy date format (for example, I6YMD or A8MDYY). A non-date format (such as I8 or A6). A non-date format in infmt functions as an offset from the base date of a YYMD field (12/31/1900).
outfmt - AlphanumericIs the output format enclosed in single quotation marks. It is one of the following:
A non-legacy date format (for example, YYMD, YQ, M, DMY, JUL). A legacy date format (for example, I6YMD or A8MDYY). A non-date format (such as I8 or A6). A non-date format in infmt functions as an offset from the base date of a YYMD field (12/31/1900).
Outfield - AlphanumericIs the field that contains the result. This value is required only for Maintain.
What's New With Dates Review – Functions
Copyright 2007, Information Builders. Slide 16
DATEADD(date, 'unit', #units[, outfield]) Function adds a unit to or subtracts a unit from a date format DATEADD(NEW_DATE, 'WD', 3)
where: date - Is any day-based non-legacy date, for example, YYMD, MDY, or JUL.
unit – AlphanumericIs one of the following enclosed in single quotation marks:
Y indicates a year unit.M indicates a month unit.D indicates a day unit.WD indicates a weekday unit. BD indicates a business day unit.
#units – IntegerIs the number of date units added to or subtracted from date. If this number is not a whole unit, it is rounded down to the next largest integer.
outfield – AlphanumericIs the field that contains the result. This value is required only for Maintain.
What's New With Dates Review – Functions
Copyright 2007, Information Builders. Slide 17
HDTTM(date, length, outfield) Function converts a date value to a date‑time fieldHDTTM(TRANSDATE_DATE, 8, 'HYYMDIA')
where:
date - Is the date value to be converted, the name of a date field that contains the value, or an expression that returns the value.
length - Is the length of the returned date‑time value. Valid values are:8 indicates a time value that includes milliseconds. 10 indicates a time value that includes microseconds.
Outfield - AlphanumericIs the field that contains the result, or the format of the output value enclosed in single quotation marks. The format must be in date-time format (data type H).In FOCUS, you must specify the format. In Maintain, you must specify the name of the field.
What's New With Dates Review – Functions
Copyright 2007, Information Builders. Slide 18
HPART(value, 'component', outfield) Function extracts a specified component from a date‑time value and returns it in numeric formatHPART(TRANSDATE, 'DAY', 'I2')
where: value - Is a date‑time value, the name of a date‑time field that contains the value, or an expression that returns the value.
component - Is the name of the component to be retrieved enclosed in single quotation marks. See Arguments for Use With Date and Time Functions for a list of valid components.
Outfield - NumericIs the field that contains the result, or the integer format of the output value enclosed in single quotation marks. In FOCUS, you must specify the format. In Maintain, you must specify the name of the field.
What's New With Dates Review – Functions
Copyright 2007, Information Builders. Slide 19
HINPUT(inputlength, 'inputstring', length, outfield) Function converts an alphanumeric string to a date‑time valueHINPUT(14, ALPHA_DATE_TIME, 8, 'HYYMDS')
where: inputlength Is the length of the alphanumeric string to be converted. You can supply the actual value, the name of a numeric field that contains the value, or an expression that returns the value.
inputstring Is the alphanumeric string to be converted enclosed in single quotation marks, the name of an alphanumeric field that contains the string, or an expression that returns the string. The string can consist of any valid date‑time input value as described in Describing Data.
length Is the length of the returned date‑time value. Valid values are:
8 indicates a time value that includes milliseconds. 10 indicates a time value that includes microseconds.
outfield - AlphanumericIs the field that contains the result, or the format of the output value enclosed in single quotation marks. The format must be in date-time format (data type H).In FOCUS, you must specify the format. In Maintain, you must specify the name of the field.
What's New With Dates Review – Functions
Copyright 2007, Information Builders. Slide 20
HDIFF(value1, value2, 'component', outfield) function calculates the number of units between two date-time valuesHDIFF(ADD_MONTH, TRANSDATE, 'DAY', 'D12.2')
where: value1 - Is the end date‑time value, the name of a date‑time field that contains the value, or an expression that returns the value.
value2 - Is the start date‑time value, the name of a date‑time field that contains the value, or an expression that returns the value.
component - Is the name of the component to be used in the calculation enclosed in single quotation marks. If the component is a week, the WEEKFIRST parameter setting is used in the calculation.
outfield - AlphanumericIs the field that contains the result, or the format of the output value enclosed in single quotation marks. The format must be floating-point double-precision.In FOCUS, you must specify the format. In Maintain, you must specify the name of the field.
What's New With Dates Review – Functions
Copyright 2007, Information Builders. Slide 21
The following component names and values are supported as arguments for the date‑time functions that require them:
Component Name Valid Valuesyear 0001‑9999 quarter 1‑4 month 1‑12 day‑of‑year 1‑366 day or day‑of‑month 1‑31 (The two names for the component are equivalent.) week 1‑53 weekday 1‑7 (Sunday‑Saturday) hour 0‑23minute 0‑59 second 0‑59 millisecond 0‑999 microsecond 0‑999999
Arguments for Use With Date and Time Functions
What's New With Dates Review – Functions
Copyright 2007, Information Builders. Slide 22
TIME Functions
HHMMSS – retrieves the current time
DATETIME Functions
HADD – increments a date-time valueHDATE – converts the date portion of a date-time value to a date formatHGETC – retrieves the current date and time in a date-time fieldHNAME – retrieves a date-time component in alphanumeric formatHTIME – extracts the time portion of a date-time value to a numberHYYWD – returns the year and week number from a date-time value
DATE Functions
DATEDIF – finding the difference between two datesTODAY – returns the current dateDATEMOV – moving a date to a significant point DATETRAN – format dates in international formats
What's New With Dates
Copyright 2007, Information Builders. Slide 23
HHMMSS(outfield) Retrieves the current time
HHMMSS('A8')
CURTIME/A8=HHMMSS('A8');Output: 09.20.13
where: outfield – Alphanumeric, at least 8 charactersIs the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.
In Dialogue Manager you must specify the format. In Maintain, you must specify the name of the field.
What's New With Dates TIME Functions
Copyright 2007, Information Builders. Slide 24
HADD(infield, 'component', increment, length, outfield) Increments A Date-Time ValueHADD(TRANSDATE,'MONTH',1,8,'HYYMDS')
where: infield – Date-TimeIs the date-time value to be incremented, the name of a date-time field that contains the value or an expression that returns the value.
component – AlphanumericIs the name of the component to be incremented enclosed in single quotation marks.See Arguments for Use With Date and Time Functions for a list of valid components.
increment – IntegerIs the number of units by which to increment the component, the name of a numeric field that contains the value, or an expression that returns the value.
length – IntegerIs the length of the returned date-time value. Valid values are:
8 indicates a time value that includes milliseconds10 indicates a time value that includes microseconds
outfield – Date-TimeIs the field that contains the result, or the format of the output value enclosed in single quotation marks. It must be a DATE-TIME format. In Maintain, the name of the field is required.
What's New With Dates DATETIME Functions
Copyright 2007, Information Builders. Slide 25
HADD example
Input date of STDATE is 2008/09/23 15:30:00.000
STDATE plus 2 months is derived using:
STDATEP2M/HYYMDs=HADD(STDATE,'MONTH',2,10,'HYYMDs');
The result is:
2008/11/23 15:30:00.000
What's New With Dates DATETIME Functions
Copyright 2007, Information Builders. Slide 26
HDATE(value, '(YYMD)', outfield) Converts the date portion of a Date-Time field to a Date valueHDATE(DATETIMEFLD,outfield)
where: value – Date-TimeIs the date-time value to be converted, the name of a date-time field that contains the value, or an expression that returns the value.
outfield – YYMD For Maintain, this is the name of the output field otherwise it will be YYMD.
What's New With Dates DATETIME Functions
HADD example:
Input date of STDATE is 2008/09/23 15:30:00.000
DATEONLY/YYMD=HDATE(STDATE,'YYMD');
The result is:
2008/09/23
Copyright 2007, Information Builders. Slide 27
HGETC(length, outfield) Stores current date-time into a date-time field.HGETC(8, 'HYYMDs')
where: length – IntegerIs the length of the returned date-time value. Valid values are:
8 – indicates a time value that includes milliseconds10 – indicates a time value that includes microseconds
outfield – date-time Is the field that contains the result, or format or the output value enclosed in single quotation marks. The format must be in date-time format (data type H). In Maintain, you must specify the name of the field.
What's New With Dates DATETIME Functions
HGETC example:
CURRDATETIME/HYYMDs=HGETC(10,'HYYMDs');
The result is:
2009/04/21 09:32:35.215
Copyright 2007, Information Builders. Slide 28
HTIME(length, value, outfield) Converts the time portion of a datetime value to a valueHTIME(8,TRANSDATE, 'D12.2')
where:
length – IntegerIs the length of the input date‑time value. Valid values are:
8 indicates a time value that includes milliseconds. 10 indicates a time value that includes microseconds.
value – Date-TimeIs the date-time value from which to convert the time, the name of a date-time field that contains the value, or an expression that returns the value.
outfield – Floating Point or Double Precision numberIs the field that contains the result, or the format of the output value enclosed in single quotation marks. The format must be floating point or double precision. In Maintain, you must specify the name of the field.
What's New With Dates DATETIME Functions
Copyright 2007, Information Builders. Slide 29
HNAME(value, 'component', outfield) Function extracts a specified component from a date‑time value and returns it in alphanumeric formatHNAME(TRANSDATE, 'DAY', 'A20')
where: value - Is a date‑time value, the name of a date‑time field that contains the value, or an expression that returns the value.
component - Is the name of the component to be retrieved enclosed in single quotation marks. See Arguments for Use With Date and Time Functions for a list of valid components.
Outfield – Alphanumeric, at least A2Is the field that contains the result, or the alphanumeric format of the output value enclosed in single quotation marks. In Maintain, you must specify the name of the field.The function converts all the other components to strings of digits only. The year is always four digits and the hour assumes the 24-hour system.
What's New With Dates DATETIME Functions
Copyright 2007, Information Builders. Slide 30
HNAME example
Input date of STDATE is 2008/09/23 15:30:00.000
Extracting Month from date-time:
STDATEP2M/HYYMDs=HADD(STDATE,'MONTH',2,10,'HYYMDs');
The result is:
2008/11/23 15:30:00.000
What's New With Dates DATETIME Functions
Copyright 2007, Information Builders. Slide 31
HADD example
Input date of STDATE is 2008/09/23 15:30:00.000
STDATE plus 2 months is derived using:
EXTMONTH/A20=HNAME(STDATE, 'MONTH', 'A20');
The result is:
SEP
What's New With Dates DATETIME Functions
Copyright 2007, Information Builders. Slide 32
HYYWD(dtvalue, outfield) Returns the year and week number from a date-time valueHYYWD(OPEN_DT, 'A10')
2008/09/23 15:30:00.000where: Output: 2008-W38-4 dtvalue – date-time Is the date-time value to be edited, the name of a date-time field that contains the value, or, or an expression that returns the value.
outfield - AlphanumericIs the field that contains the result, or the format of the output value enclosed in single quotation marks.
The field must be at least 10 characters long. The output is in the following format:
yyyy-Www-d
where: yyyy – is the four digit year ww – is the two digit week number (01 – 53) d – is the single digit day of the week (1 to 7). The d value is relative to the current WEEKFIRST setting. If WEEKFIRST is 2 or ISO2 (Monday), then Monday is represented in the output as 1, Tuesday as 2.
Using the EDIT function, you can extract the individual subfields from this output.
What's New With Dates DATETIME Functions
Copyright 2007, Information Builders. Slide 33
DATEDIF(from_date, to_date, 'unit', outfield) Calculates the number of units between two date-time valuesDATEDIF(BEGDATE,ENDDATE, 'M',, 'D12.2')
where: from_date – DateIs the start date from which to calculate the difference.
to_date – DateIs the end date from which to calculate the difference.
unit – AlphanumericIs one of the following enclosed in single quotation marks:
Y for year WD for weekdayM for month BD for business dayD for day
outfield - NumericIs the name of the field that contains the result, or the format of the output value enclosed in single quotation marks. In Maintain, you must specify the name of the field.
What's New With Dates DATE Functions
Copyright 2007, Information Builders. Slide 34
TODAY(outfield) Returns the current dateTODAY('A8')
where:
outfield – Alphanumeric, at least A8Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks. The following apply:
If DATEFNS=ON and the format is A8 or A9, TODAY returns the 2 digit yearIf DATEFNS=ON and the format is A10 or greater, TODAY returns the 4 digit yearIf DATEFNS=OFF, TODAY returns the 2 digit year, regardless of the format of outfield
In Dialogue Manager, you must specify the format. In Maintain, you must specify the name of the field.
What's New With Dates DATE Functions
Copyright 2007, Information Builders. Slide 35
DATEMOV(date, 'move-point') Moves a date to a significant pointDATEMOV(OPENDATE,'BOM')
where: from_date – DateIs the date to be moved.
move-point – AlphanumericIs the significant point the date is moved to enclosed in single quotation marks. An invalid point results in a return code of zero. Valid values are:
EOM – end of month NWD – next weekdayBOM – beginning of month NBD – next business dayEOQ – end of quarter PWD – prior weekdayBOQ – beginning of quarter PBD – prior business dayEOY – end of year WD- – weekday or earlierBOY – beginning of year BD- – business day or earlierEOW – end of week WD+ - weekday or later BOW – beginning of week BD+ - business day or later
Business day calculations are affected by BUSDAYS and HDAY.
What's New With Dates DATE Functions
Copyright 2007, Information Builders. Slide 36
DATETRAN(indate, '(intype)', '(formatopts)', 'lang', outlen, outfield) Formats dates in International formatsDATETRAN(DATEFIELD, '(MDYY)', '(wrctrdo)', 'EN', 150, FMTDATE)will print: Tuesday, March 17th 2009
where: indate – DateIs the date to be formatted.
intype – AlphanumericIs the format that the date will be displayed in.
formatopts – AlphanumericIdentifies the formatting to take place. Suppression formats
m – Zero suppresses months (display numeric months before October as 1 to 9 rather than 01 through 09).d – Zero suppresses days.dp – same as d with a period after the daydo – Zero suppresses days, for English will print the ordinal suffix after
the number.
What's New With Dates DATE Functions
Copyright 2007, Information Builders. Slide 37
formatopts – continued
Month and Day Name translations:T – displays month abbreviated, all uppercase, no punctuation. (JAN)TR – display full month, all uppercase. (JANUARY)Tp – same as T with a period after the abbreviated month. (JAN.)t – displays abbreviated month, no punctuation, first character is
capital based on language setting. (Jan)tr – displays full month, all lowercase, first character uppercase based
on language setting. (January)tp – same as t with period after abbreviated month. (Jan.)W – abbreviated day of the week name before the displayed date,
all upper case, no punctuation. (TUE)WR – full day of week before the date, all uppercase. (TUESDAY)Wp – same as W with period after abbreviated weekday. (TUE.)w – abbreviated day of week, lowercase, first character capital based
on language setting. (Tue)wr – full day of week, all lowercase, first character capital based
on language setting. (Tuesday)wp – same as w with period after abbreviated weekday. (Tue.)
What's New With Dates DATE Functions
Copyright 2007, Information Builders. Slide 38
formatopts – continued
X – displays abbreviated day of the week at the end of the displayed date, all uppercase, no punctuation. (WED)
XR – display full day of the week after date, all uppercase. (WEDNESDAY)Xp – same as X with a period after the abbreviated weekday. (WED.)x – displays abbreviated weekday after date, no punctuation, first character is
capital based on language setting. (Wed)xr – displays full weekday after date, all lowercase, first character
uppercase based on language setting. (Wednesday)xp – same as x with period after abbreviated weekday. (Wed.)
Delimiter options:B – use a blank as delimiter. Default for month or day of week. . – use a period as delimiter- – use a minus sign as delimiter. This is the default when conditions for
a blank are not satisfied. / – use a slash as the delimiter| – omits delimitersK – Use comma after month name, comma space after the day name
What's New With Dates DATE Functions
Copyright 2007, Information Builders. Slide 39
formatopts – continued
c – places comma after the month name, or comma blank after day name.e – displays the Spanish or Portuguese word de or DE between the day
and month and between the month and year.D –Inserts comma after the day name and before the general delimiterY – Inserts a comma after the year and before the general delimiter
lang – Alphanumericthe two character standard ISO code for the language into which the date should be translated, enclosed in single quotation marks. Valid language codes are:
AR Arabic EL Greek PO PolishCS Czech IW Hebrew PT PortugueseDA Danish IT Italian RU RussianDE German JA Japanese SV SwedishEN English KO Korean TH ThaiES Spanish LT Lithuanian TW Chinese (Traditional)FI Finnish NL Dutch ZH Chinese (Simplified)FR French NO Norwegian
What's New With Dates DATE Functions
Copyright 2007, Information Builders. Slide 40
outlen – NumericThe length of the output field in bytes. If the length is insufficient, an all blank result is returned. If the length is greater than required, the field is padded with blanks on the right.
output – AlphanumericIs the name of the field that contains the translated date, or it format enclosed in single quotation marks.
What's New With Dates DATE Functions
Copyright 2007, Information Builders. Slide 41
Questions?
What's New With Dates
Thank you for coming!