Focal Point
(SOLVED) Date Conversion

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

January 17, 2017, 04:25 PM
tomatosauce
(SOLVED) Date Conversion
Hi All,

I am kind of struck in the middle for this date conversion.

I am getting my last week's end of week date and last week's beginning of week date from the following code.

 
-SET &LW=DATEADD(DATECVT(AYMD(&YYMD,-7,'I8MDYY'),'I8YYMD','YYMD'),'D',0);
-SET &LW_EOW=DATECVT(DATEADD(DATEMOV(&LW,'EOW'),'D','1'),'YYMD','I8MDYY');
-SET &LW_BOW=DATECVT(DATEADD(DATEMOV(&LW,'BOW'),'D','-1'),'YYMD','I8MDYY');
 


It gives me the following values
LW_EOW = 1142017
LW_BOW = 1082017

I want to convert this date to MM/DD/YYYY like 01/14/2017 or 01/08/2017

For Oct - Dec i used to run the following code and it was working fine.

-SET &LW_EOW_DATE = EDIT(&LW_EOW, '99$')|'/'| EDIT(&LW_EOW, '$$99')|'/' | EDIT (&LW_EOW, '$$$$9999');

For Month it returns just the single digit for Jan-Sep (1-9).
So i added a 0 in the following EDIT function
and it does the trick.

-SET &LW_EOW_DATE = EDIT(&LW_EOW, '09$')|'/'| EDIT(&LW_EOW, '$99')|'/' | EDIT (&LW_EOW, '$$$9999');

But is there any way i can do it without hardcoding the value 0 in front of month's value?

I know it might be simple but i cant figure out. Any help would be appreciated.

This message has been edited. Last edited by: tomatosauce,


Tharun Katanguru
SBOX- 8205 DEV/TEST/PROD : 8105 8205
Linux, All Outputs
January 17, 2017, 04:42 PM
Francis Mariani
-SET &LW     = DATECVT( DATEADD( DATECVT(&YYMD,'I8YYMD','YYMD') ,'D', -7), 'YYMD','I8YYMD');
-SET &LW_BOW = DATECVT( DATEMOV( DATECVT(&LW,'I8YYMD','YYMD') ,'BOW'),'YYMD','I8YYMD');
-SET &LW_EOW = DATECVT( DATEMOV( DATECVT(&LW,'I8YYMD','YYMD') ,'EOW'),'YYMD','I8YYMD');

-? &LW

The inner DATECVT converts a string to a date. Then the DATEADD/DATEMOVE function is applied. Then the outer DATECVT converts the resulting date back to a string.

This message has been edited. Last edited by: Francis Mariani,


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
January 17, 2017, 04:43 PM
jcannavo
Francis beat me to it. That inner DATECVT is what you are missing.


JC
WebFOCUS Dev Studio / App Studio
8.2.01
Windows 7
January 17, 2017, 05:19 PM
tomatosauce
Arghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh!!!

Got it to work.

-SET &LW = DATECVT( DATEADD( DATECVT(&YYMD,'I8YYMD','YYMD') ,'D', -7), 'YYMD','I8YYMD');
-SET &LW_BOW = DATECVT(DATEADD( DATEMOV( DATECVT(&LW,'I8YYMD','YYMD') ,'BOW'),'D','-1'),'YYMD','I8YYMD');
-SET &LW_EOW = DATECVT(DATEADD( DATEMOV( DATECVT(&LW,'I8YYMD','YYMD') ,'EOW'),'D','1'),'YYMD','I8YYMD');

-SET &LW_EOW_DATE = EDIT(&LW_EOW, '$$$$99')|'/'| EDIT(&LW_EOW, '$$$$$$99')|'/' | EDIT (&LW_EOW, '9999$');
-SET &LW_BOW_DATE = EDIT(&LW_BOW, '$$$$99')|'/'| EDIT(&LW_BOW, '$$$$$$99')|'/' | EDIT (&LW_BOW, '9999$');

Thanks for the input Francis & jcannavo. I really admire your Knowledge and service to the WF Community.


Tharun Katanguru
SBOX- 8205 DEV/TEST/PROD : 8105 8205
Linux, All Outputs
January 17, 2017, 05:38 PM
David Briars
@Francis - Loved the way you highlighted the three functions; to help show that/how they are interrelated.
January 17, 2017, 10:51 PM
Francis Mariani
Thanks David. Not something you can find in the functions manual.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
January 18, 2017, 01:07 AM
Danny-SRL
As I suggested in another post Let's Date :
all this converting should be much simplified!


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

January 18, 2017, 10:42 AM
Francis Mariani
It appears IBI is making an attempt at simplifying date functions:

In the documentation WebFOCUS Release 8.1 Version 05M > Reporting Language > Using Functions > Simplified Date and Date-Time Functions, it is explained:

quote:
Simplified date and date-time functions have streamlined parameter lists, similar to those used by SQL functions. In some cases, these simplified functions provide slightly different functionality than previous versions of similar functions.
The simplified functions do not have an output argument. Each function returns a value that has a specific data type.
When used in a request against a relational data source, these functions are optimized (passed to the RDBMS for processing).
Standard date and date-time formats refer to YYMD and HYYMD syntax (dates that are not stored in alphanumeric or numeric fields). Dates not in these formats must be converted before they can be used in the simplified functions. Literal date-time values can be used with the DT function.
All arguments can be either literals, field names, or amper variables.
Note: The simplified date and date-time functions are not supported in WebFOCUS Maintain.

From this description, it appears strings can be used in the functions. We're on ancient v8.0.08 so I haven't tested the benefits of these newish "simplified" functions.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server