Focal Point
[SOLVED] Obtain month from a date.

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

June 16, 2005, 08:03 PM
newtofocus
[SOLVED] Obtain month from a date.
What function do I use to extract month out of a date?

Thanks.

This message has been edited. Last edited by: Tamra,
June 16, 2005, 08:09 PM
jimster06
Depends on the format of the date and the format desired for the month.

In the upper right of this screen, click on 'Technical Documentation Library' and search for date functions; you should be able to get more than enough information.

HTH
June 16, 2005, 08:15 PM
newtofocus
The format in the MFD is defined as DATE and the source is a DB2 table.

Thx.
June 17, 2005, 04:36 PM
TerryW
In that case, just create a DEFINE with the Month format:

DEFINE FILE TABLENAME
MONTH/M = DATEFIELD;
END

TABLE FILE TABLENAME
PRINT MONTH
END
June 19, 2005, 12:02 AM
TexasStingray
I'm not sure if what Terry provided will work with DATE. If the format is as FOCUS smart date it should. There are 2 formats in the master file description something like

FIELDNAME=MYDATE,MDATE,HYYMDs,DATE,$

Is DATE the first or second and if the second what is the first.
January 24, 2017, 05:00 PM
Kevin Patterson
It took me 45 minutes to figure this out, but here is what I had to do:

The date I wanted to extract the month from was in an HYYMDS format. I'll call it BEGIN_DATE. I had to use HDATE to get it in a usable format. Then I simply used that field to populate a new field that had the format of M.

BEGIN_DATE_NEW_FORMAT/MDYY=HDATE(BEGIN_DATE, 'MDYY');
RPT_MTH/M=BEGIN_DATE_NEW_FORMAT;


Kevin Patterson
Appalachian State University
WebFOCUS 7.7.03
Windows, All Outputs
January 24, 2017, 06:02 PM
Francis Mariani
You may be able to use a single function using HPART:

MY_DATE_TIME_M/M = HPART(MY_DATE_TIME, 'MONTH', 'I2');



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 25, 2017, 08:16 AM
Mike in DeLand
I always joke that WebFocus is great for giving us easy ways of doing hard things, but the easy things are hard to do. Dates are a perfect example. I have to refer to the documentation every single time I have to do anything with a date field. That said, it always works out ok in the end.


Webfocus 8
Windows, Linux
January 25, 2017, 08:17 AM
Squatch
quote:
Originally posted by Kevin Patterson:
It took me 45 minutes to figure this out...

That's a pretty fast time in which to solve a WebFOCUS date problem.


App Studio
WebFOCUS 8.1.05M
Windows, All Outputs
January 25, 2017, 08:22 AM
Squatch
quote:
Originally posted by Mike in DeLand:
I have to refer to the documentation every single time I have to do anything with a date field.

I have to refer to this forum every single time I have to do anything with a date field. The IBI documentation and the infamous 3rd party book dedicated to WebFOCUS dates just muddies the date waters even more, in my opinion.


App Studio
WebFOCUS 8.1.05M
Windows, All Outputs
January 25, 2017, 09:48 AM
RSquared
I try to copy my date functions into a document and then try to remember where I put that document


WF 7.6.11
Oracle
WebSphere
Windows NT-5.2 x86 32bit
January 25, 2017, 11:48 AM
Wep5622
I'm quite happy with the new 'Simplified' versions of functions, such as the Simplified date and time functions: http://infocenter.informationb.../source/topic168.htm

Referring back to another ongoing thread about week numbers (assuming ISO8601 weeks here): Unfortunately these functions do provide an incantation to get the week number of the year, but they lack the ability to tell what year that week belongs to.

For example, January 1st would correctly return week 53 for those weeks that started in December in the previous year, but it would return this year with that week number instead of last year. That's a bit nasty because there are only a couple of weeks per year that you can find out that you made that mistake! And it doesn't happen every year either, this year being a good example.


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :