Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn YouTube
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Extract month and year from date
Go
New
Search
Notify
Tools
Reply
  
[SOLVED] Extract month and year from date
 Login/Join
 
Member
posted
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
 
Posts: 28 | Registered: September 05, 2017Reply With QuoteReport This Post
Member
posted Hide Post
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,
 
Posts: 10 | Location: Bangalore | Registered: July 31, 2018Reply With QuoteReport This Post
Guru
posted Hide Post
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.
 
Posts: 411 | Location: Europe | Registered: February 05, 2007Reply With QuoteReport This Post
Virtuoso
posted Hide Post
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.0.1M gen 240, Dev 8.2.04 gen 48, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
 
Posts: 2233 | Location: Montreal Area, Qc, CA | Registered: September 25, 2013Reply With QuoteReport This Post
Expert
posted Hide Post
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.
 
Posts: 3045 | Location: Middle Tennessee [8204M Gen48 in Test&Prod] | Registered: February 23, 2005Reply With QuoteReport This Post
Virtuoso
posted Hide Post
 
Posts: 1716 | Location: New York City | Registered: December 30, 2015Reply With QuoteReport This Post
Gold member
posted Hide Post
@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
 
Posts: 62 | Registered: January 23, 2018Reply With QuoteReport This Post
Guru
posted Hide Post
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.
 
Posts: 411 | Location: Europe | Registered: February 05, 2007Reply With QuoteReport This Post
Expert
posted Hide Post
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.06 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
 
Posts: 5617 | Location: United Kingdom | Registered: April 08, 2004Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Extract month and year from date

Copyright © 1996-2018 Information Builders, leaders in enterprise business intelligence.