Focal Point
Alpha to Date Conversion

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/1821075282

May 01, 2008, 05:04 PM
ColdWhiteMilk
Alpha to Date Conversion
I'm using WebFOCUS 7.6.4.

I've used the Zulu Time article to convert the Epoch time to a "normal" date format. Now I need to convert that resulting A20 field to a date field that I can compare against "today" in my criteria.

I've got:
CYCLSTART/A20 = HCNVRT(FOCUSDATEST,'(HYYMDIA)',20,'A20');
CYCLSTART1/I8MDYY = DATECVT ( CYCLSTART , 'MDYY' , 'I8MDYY' ) ;
CYCLSTART2/A15 = EDIT ( CYCLSTART1 , '99/99/9999' ) ;

This gives me an error message about an invalid arguement in #1 of DATECVT.

Does anyone know how to do this conversion?

Thank you.


Production - 7.6.4
Sandbox - 7.6.4
May 01, 2008, 05:22 PM
N.Selph
I use

 
STDATE_A1/A20= HCNVRT(STDATE2,'(HYYMDIA)',20,'A20');
STDATE_A/A20= GETTOK(SQUEEZ(20,STDATE_A1,'A20'),20,1,' ',20,'A20');

and

WHERE STDATE_A EQ '&DATEYYMD'
 



(Prod: WebFOCUS 7.7.03: Win 2008 & AIX hub/Servlet Mode; sub: AS/400 JDE; mostly Self Serve; DBs: Oracle, JDE, SQLServer; various output formats)
May 01, 2008, 11:34 PM
Waz
There are many ways to get the current date.

HGETC will give you the current Date and Time

&YYMD will get you the date when the session started (depends on how long your request takes to run).

I think it may be better to get the current date into a smart date (Format YYMD) and test against that, you can use HDATE to covert your DateTime to a Date.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

May 02, 2008, 09:24 AM
ColdWhiteMilk
I'm still pretty new to WebFOCUS.

I know how to get today's date. My concern is whether the "CYCLSTART/A20 = HCNVRT(FOCUSDATEST,'(HYYMDIA)',20,'A20');" define results in a value that can be compared to today's date.


Production - 7.6.4
Sandbox - 7.6.4
May 02, 2008, 02:51 PM
FrankDutch
If you are new to focus I would suggest you buy a very good book on dates.
"Almost 1001 Ways to work with DATES in WebFOCUS"
it's worth all the money.
And there are some great PDF files available on the Information Builders website.

An other suggestion is to upgrade your signature with information about the systems you use (version etc)




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

May 04, 2008, 07:03 AM
Danny-SRL
Hi,

If you use the following in your DEFINE command:
  
CYCLSTART/A10 = HCNVRT(FOCUSDATEST,'(HYYMD)',10,'A10');

You will get your date in alpha format with slashes
Then in your TABLE command, you can use
  
WHERE CYCLSTART EQ '&DATEYYMD';


I hope this helps you.


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

May 06, 2008, 01:04 PM
Brian Suter
RE: the original error ... DATECVT can take "smart dates" (which internally are integers with number of days since 1900), old alpha dates or old interger dates.
CYCLSTART is NOT a new date, it is an alpha, so datecvt knows that and tells you. This should work:
DATECVT ( CYCLSTART , 'A8MDYY' , 'I8MDYY' ) ;


Brian Suter
VP WebFOCUS Product Development
May 06, 2008, 04:03 PM
Darin Lee
The one issue with Daniel's solution is that you end up doing a selection on a DEFINED field, so there is a significant drop in efficiency, as those criteria cannot be passed to the DBMS. It's always better to make your variable format match the format of your real database field instead of the other way around.


Regards,

Darin



In FOCUS since 1991
WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex
Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex
WF Client: 77 on Linux w/Tomcat
August 12, 2008, 02:35 PM
PHawk
I get the same error ( invalid arguement in #1 of DATECVT) in 7.6.6 using:

CURDATE/HMDYY=HGETC(10,'HYYMD');
2DATE/YYMD=HDATE(CURDATE,'YYMD');
MONTH/M=DATECVT(2DATE,'YYMD','YYMD');
YEAR/YY=DATECVT(2DATE,'YYMD','YYMD');

This same code works in 7.1.6, any ideas why DATECVT has changed?
August 12, 2008, 03:13 PM
j.gross
quote:

CURDATE/HMDYY=HGETC(10,'HYYMD');
2DATE/YYMD=HDATE(CURDATE,'YYMD');
MONTH/M=DATECVT(2DATE,'YYMD','YYMD');
YEAR/YY=DATECVT(2DATE,'YYMD','YYMD');


Perhaps it's complaining that you are not asking DATECVT to "convert" anything -- arg 2 and 3 are identical!

But once you have a date variable, you don't need DATECVT to extract month or year -- just cast it directly:

MONTH/M=2DATE;
YEAR/YY=2DATE;


- Jack Gross
WF through 8.1.05
August 12, 2008, 03:16 PM
susannah
PHawk,
if infact 2DATE is already a smart date,
then
MONTH/M = 2DATE;
YEAR/YY = 2DATE;
is all in the world you need.
Smart dates are so so so easy to format.Wink




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
August 12, 2008, 03:18 PM
PHawk
Well I have the same situation in this date conversion:

SERYMA/A4=SUBSTR(30, F4220V1.F4220V1.SERIAL_NUMBER_1, 3, 6, 4, SERYMA);
CURDATE/MDYY=&MDY;
CURYM/YM=CURDATE;
SERYM/YM=DATECVT(SERYMA, 'A4YM', 'YM');
MTHINV/D4=CURYM-SERYM;

On our old server this would tell us how many months are between the two dates, but on the new server I got the same error about an invalid arguement in #1 of DATECVT.

I fixed this report by doing some different conversions but the root of the problems is the function DATECVT.

My changes:

SERYMA/A4=SUBSTR(30, F4220V1.F4220V1.SERIAL_NUMBER_1, 3, 6, 4, SERYMA);
CURDATE/HYYMDHA=HGETC(8, CURDATE);
YEAR/Y=HPART(CURDATE, 'YEAR', YEAR);
MONTH/M=HPART(CURDATE, 'MONTH', MONTH);
SERYYEAR/A2=EDIT(SERYMA,'99$$');
CURYYEAR/A2=EDIT(YEAR,'99');
SERYYEAR2/I2=EDIT(SERYYEAR);
CURYYEAR2/I2=EDIT(CURYYEAR);
SERYMON/A2=EDIT(SERYMA,'$$99');
CURYMON/A2=EDIT(MONTH,'99');
SERYMON2/I2=EDIT(SERYMON);
CURYMON2/I2=EDIT(CURYMON);
MTHINV/I3=((CURYYEAR2 * 12) + CURYMON2) - ((SERYYEAR2 * 12) + SERYMON2);
August 12, 2008, 05:06 PM
j.gross
It works with A6YYM, just not A4YM (even with DFC and YRT specified in the Define). That's a bug.

- - - -
http://documentation.ibi.com/masterindex/html/html_iway...unctions76/date6.htm

Syntax: How to Convert the Format of a Date
DATECVT(date, in_format, out_format)

where:

date Is the date to be converted. ... When the conversion is performed, a legacy date obeys any DEFCENT and YRTHRESH parameter settings supplied for that field.

- - - -
But if you declare it as /A4YM, you can directly cast it to a year-month smart date without resorting to DATECVT:
DEFINE FILE CAR
 SERYMA/A4YM WITH COUNTRY=EDIT('&YMD','9999');
 SERYM/MTYY DFC 19 YRT 50 =SERYMA;
END
TABLE FILE CAR
PRINT SERYMA SERYM 
IF RECORDLIMIT EQ 1
END

This message has been edited. Last edited by: j.gross,


- Jack Gross
WF through 8.1.05
August 18, 2008, 12:02 PM
Doug
Consider this: -SET the dates which you want to pass in to the DBMS before your DEFINE or TABLE.

Example:

-SET &ReportEndDate = DATECVT(&MDYY,'I8MDYY','MDYY');
-SET &ReportEndDate = DATEADD(&ReportEndDate, 'D', -1);
-SET &ReportEndDate = DATECVT(&ReportEndDate,'MDYY','A8MDYY');
-SET &ReportEndMonth = EDIT(&ReportEndDate,'99') ;
-SET &ReportEndYear = EDIT(&ReportEndDate,'$$$$9999') ;
-* Offset the year as required
-SET &ReportEndYear = IF &ReportEndMonth GE '10' THEN &ReportEndYear - 1
- ELSE &ReportEndYear ;
-SET &ReportEndDate = IF &ReportEndMonth GE '10' THEN '0930' || &ReportEndYear
- ELSE EDIT(&ReportEndDate,'9999') || &ReportEndYear ;

The EDITs can be changed to fit whtaever format your DBMS requires. Try it, you'll like it...

And, Yes, "Almost 1001 Ways to work with DATES in WebFOCUS" is worth the money




   In FOCUS Since 1983 ~ from FOCUS to WebFOCUS.
   Current: WebFOCUS Administrator at FIS Worldpay | 8204, 8206