Focal Point
[SOLVED] Extract month and year from date

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

August 27, 2018, 05:38 PM
Gagan Marwah
[SOLVED] Extract month and year from date
I have a date column that displays date in the following format:
10/13/2011 13:59:49

I would like to extract only month and year from the date. What Date-Time function would work in this situation?

Thank you

This message has been edited. Last edited by: FP Mod Chuck,


WebFOCUS 8
Windows, All Outputs
August 28, 2018, 12:21 AM
Darshan Patil
Hi Gagan,
The following maybe one of the way to extract the month and year from date-time component.

DEFINE FILE CAR
DATE/HYYMDS WITH CAR= HGETC(10,'HYYMDS');
TRANSDATE_DATE/YYMD = HDATE(DATE, 'YYMD');
YEAR/YY=TRANSDATE_DATE;
MONTH/M=TRANSDATE_DATE;
END
TABLE FILE CAR
PRINT DATE TRANSDATE_DATE MONTH YEAR
BY TOP 1 CAR NOPRINT
END

HDATE converts date-time value to date format.

OR you can use FPRINT and EDIT functions,FPRINT converts date to alphanumeric and EDIT can mask unwanted values.

DEFINE FILE CAR
DATE/HYYMDS= HGETC(10,'HYYMDS');
ALPHA_DATE/A10= FPRINT(DATE,'HYYMDS','A10');
YEAR/A4=EDIT(ALPHA_DATE,'9999$$$$$$');
MONTH/A2=EDIT(ALPHA_DATE,'$$$$$99$$$');
END
TABLE FILE CAR
PRINT DATE MONTH YEAR
BY TOP 1 CAR NOPRINT
END

This message has been edited. Last edited by: Darshan Patil,
August 28, 2018, 05:36 AM
Frans
Better use DTPART in order to get SQL optimization:

DEFINE FILE ...
YEAR/I4=DTPART(DATETIMECOLUMN,YEAR);
MONTH/I2=DTPART(DATETIMECOLUMN,MONTH);
END


Test: WF 8.2
Prod: WF 8.2
DB: Progress, REST, IBM UniVerse/UniData, SQLServer, MySQL, PostgreSQL, Oracle, Greenplum, Athena.
August 28, 2018, 07:46 AM
MartinY
Below should also work with smartdate
DEFINE FILE abc
-* numeric year
THE_YEAR /YY = YourDateField;
-* numeric month
THE_MM /MONTH = YourDateField;
-* Alpha long month mixed case
THE_Month /Mtr = YourDateField;
-* Alpha long month upper case
THE_MONTH /MTR = YourDateField;
-* Alpha short month mixed case
THE_Mth /Mt = YourDateField;
-* Alpha short month upper case
THE_MTH /MT = YourDateField;
END


WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
August 28, 2018, 08:27 AM
Doug
Checkout hpart or hdate, as mentioned above. Are you using IA or AS? You may be able to get this info at http://localhost:8080/ibi_apphelp/index.jsp, F1 from within AS.
August 28, 2018, 09:35 AM
BabakNYC
https://webfocusinfocenter.inf...ateSimplified175.htm


WebFOCUS 8206, Unix, Windows
August 28, 2018, 01:18 PM
vinodh
@Gagan Marwah....this is the easiest and best way .....
quote:
Originally posted by MartinY:
Below should also work with smartdate
DEFINE FILE abc
-* numeric year
THE_YEAR /YY = YourDateField;
-* numeric month
THE_MM /MONTH = YourDateField;
-* Alpha long month mixed case
THE_Month /Mtr = YourDateField;
-* Alpha long month upper case
THE_MONTH /MTR = YourDateField;
-* Alpha short month mixed case
THE_Mth /Mt = YourDateField;
-* Alpha short month upper case
THE_MTH /MT = YourDateField;
END



WebFOCUS 8
Windows, All Outputs
August 29, 2018, 03:42 AM
Frans
quote:
Originally posted by vinodh:
@Gagan Marwah....this is the easiest and best way


It's easy, but why do you think it's the best way?


Test: WF 8.2
Prod: WF 8.2
DB: Progress, REST, IBM UniVerse/UniData, SQLServer, MySQL, PostgreSQL, Oracle, Greenplum, Athena.
August 29, 2018, 07:54 AM
Tony A
quote:
It's easy, but why do you think it's the best way?


... because they have never looked at the SQL trace to see how much of the code is translated to SQL! Wink

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10