Focal Point
[SOLVED]DTPART Function

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

June 21, 2016, 02:47 PM
Trudy
[SOLVED]DTPART Function
I am using the following code to get the month component and it is returning a value of 11 for the current date 2016/06/21

  
DTPART(&MDYY, MONTH)


The output looks like

LoadMonth LoadDate
11 06/21/2016

Where LoadDate = &MDYY

Any ideas what I am doing wrong?

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


WF8
Windows
June 21, 2016, 02:53 PM
Trudy
&DATEM gave me the value of 6 which is at least correct. I am wondering why the DTPART and DPART functions were not returning the correct values?


WF8
Windows
June 21, 2016, 03:18 PM
MartinY
I think that the reason is because &MDYY is not a date/date time format such as explained in the F1-Help of DTPART:
Syntax: How to Return a Date or Date-Time Component in Integer Format
DTPART(date, component)
where:

date
Date or date-time

Is the date in standard date or date-time format.

component
Keyword

Is the component to extract in integer format. Valid components (and values) are:

YEAR (1-9999).
QUARTER (1-4).
MONTH (1-12).
WEEK (of the year, 1-53). This is affected by the WEEKFIRST setting.
DAY (of the Month, 1-31). 
DAY_OF_YEAR (1-366).
WEEKDAY (day of the week, 1-7). This is affected by the WEEKFIRST setting.
HOUR (0-23).
MINUTE (0-59).
SECOND (0-59.)
MILLISECOND (0-999).
MICROSECOND (0-999999).

Here a sample:
DEFINE FILE EMPDATA
MTH/I2 = DTPART(HIREDATE, MONTH); 
END
TABLE FILE EMPDATA
PRINT HIREDATE MTH
BY  PIN 
ON TABLE SET PAGE NOPAGE
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
June 21, 2016, 03:36 PM
Francis Mariani
In Dialogue Manager, &YYMD works, if it's in quotes:

-SET &CURR_MTH = DTPART('&YYMD', MONTH);
-TYPE &CURR_MTH



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
June 22, 2016, 07:11 AM
Ruchika Gusain
Hi Trudy,

In Dialog Manager command, its a good practice if you first convert it into the standard date format and then extract Month from it,

-SET &E_MONTH = DTPART(DATECVT(&MDYY,'I8MDYY','MDYY'),MONTH);
-TYPE &E_MONTH

Thanks

WebFOCUS 8