Let's Get Social!
Focal Point    Focal Point Forums    WebFOCUS/FOCUS Forum on Focal Point     Date conversion [Resolved]
 Go New Search Notify Tools Reply
 Date conversion [Resolved]
Platinum Member
 posted October 01, 2010 01:28 PM
I have gotten a timestamp to convert to the following format:

1 Sep, 10

Now, I want to convert this to:

1-Sep-10

How can I do this? I couldn't find the answer in "The Book".

This message has been edited. Last edited by: Ted Michalski,

7.7.02
Windows
EXCEL, PDF, CSV, TEXT

 Posts: 106 | Registered: June 25, 2009 IP
Platinum Member
 posted October 01, 2010 05:29 PM Hide Post
Hi Ted,

Here's an example using the CAR file. Run this and see if this would work.

-*
DEFINE FILE CAR
CNT/I3 WITH COUNTRY = CNT + 1;
C_DT/A14 = DECODE CNT (
1 '20100322053005'
2 '20000326213005'
3 '20100330023005'
4 '20090402103005'
5 '20100407233005'
ELSE '???');
END
-*
TABLE FILE CAR
PRINT
CNT
C_DT
COUNTRY
WHERE RECORDLIMIT EQ 5
ON TABLE HOLD
END
-*
DEFINE FILE HOLD
C_DTS/HYYMDS = HINPUT(14, C_DT, 8, 'HYYMDS');
C_DTS_A/A9 = HCNVRT(C_DTS, '(HDMtY)', 9, 'A9');
C_DTS_B/A9 = CTRAN(9,C_DTS_A, 32, 45, 'A9');
C_DTS_C/A9 = IF EDIT(C_DTS_A,'9') EQ '0' THEN EDIT(CTRAN(9,C_DTS_A, 32, 45, 'A9'),'\$99999999') ELSE CTRAN(9,C_DTS_A, 32, 45, 'A9');
END
-*
TABLE FILE HOLD
PRINT
CNT
C_DT
C_DTS
C_DTS_A
C_DTS_B
C_DTS_C
END

The field C_DTS_B keeps the leading zero on the day where C_DTS_C does not.

Jim

WebFocus 8.201M, Windows, App Studio

 Posts: 222 | Location: Lincoln Nebraska | Registered: August 12, 2008 IP
Guru
 posted October 01, 2010 10:05 PM Hide Post
What did you use to convert your date time to date formate? HDATE is not an option because I cant manipulate the date with it.

WebFOCUS 7.6.10
Windows
HTML

 Posts: 294 | Registered: March 04, 2010 IP
Platinum Member
 posted October 04, 2010 06:34 AM Hide Post
I used the following formula to convert the timestamp to this format:

1 Sep, 2010

VAL_DT_DISP/DMtY = HDATE(VAL_DT, 'DMtY');

7.7.02
Windows
EXCEL, PDF, CSV, TEXT

 Posts: 106 | Registered: June 25, 2009 IP
<JG>
 posted October 04, 2010 04:43 PM
quote:
/DMtY

Arif look at what was posted by jfr99
quote:
/HYYMDS

To use date functions, you must first convert to a valid internal date format.

 IP
Virtuoso
 posted October 04, 2010 10:58 PM Hide Post
I think the only way you can get the format you want is to use EDIT with HCNVRT, as jfr99 suggested earlier. You can use a straight EDIT with a mask instead of the CTRAN function, but the result is the same.

```C_DTS_C/A9 = IF EDIT(C_DTS_A,'9') EQ '0' THEN EDIT(C_DTS_A,'\$9-999\$-99') ELSE EDIT(C_DTS_A,'99-999\$-99');
```

WebFOCUS 7.7.05

 Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007 IP
Platinum Member
 posted October 05, 2010 06:52 AM Hide Post
Thanks jfr99, but it looks like your inputs are in a different format than mine. Here's what I have:

2010-09-01 00:00:00

What I want is:

1-Sep-10

7.7.02
Windows
EXCEL, PDF, CSV, TEXT

 Posts: 106 | Registered: June 25, 2009 IP
Expert
 posted October 05, 2010 02:11 PM Hide Post
Then modify what jfr99 showed you to your data and adjust the code accordingly:

```
APP APPENDPATH IBISAMP
-RUN
DEFINE FILE CAR
CNT/I3 WITH COUNTRY = CNT + 1;
C_DT/A20 = DECODE CNT (
1 '20100322 05:30:05'
2 '20000326 21:30:05'
3 '20100330 02:30:05'
4 '20090402 10:30:05'
5 '20100407 23:30:05'
ELSE '???');
END
-*
TABLE FILE CAR
PRINT
CNT
C_DT
COUNTRY
WHERE RECORDLIMIT EQ 5
ON TABLE HOLD
END
-*
DEFINE FILE HOLD
C_DTS/HYYMDS = HINPUT(20, C_DT, 8, 'HYYMDS');
C_DTS_A/A9 = HCNVRT(C_DTS, '(HDMtY)', 9, 'A9');
C_DTS_B/A9 = CTRAN(9,C_DTS_A, 32, 45, 'A9');
C_DTS_C/A9 = IF EDIT(C_DTS_A,'9') EQ '0' THEN EDIT(CTRAN(9,C_DTS_A, 32, 45, 'A9'),'\$99999999') ELSE
CTRAN(9,C_DTS_A, 32, 45, 'A9');
END
-*
TABLE FILE HOLD
PRINT
CNT
C_DT
C_DTS
C_DTS_A
C_DTS_B
C_DTS_C
END
-EXIT
```

Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe

 Posts: 1960 | Location: Centennial, CO | Registered: January 31, 2006 IP
Expert
 posted October 05, 2010 03:20 PM Hide Post
```-* File date56.fex

DT3 provides the date in the format you require, one digit day for dates before 10.

DEFINE FILE CAR
DT1/HYYMDS = HINPUT(20, '2010-09-01 00:00:00', 8, 'HYYMDS');
END

TABLE FILE CAR
PRINT
DT1
COMPUTE DT2/DMY = HDATE(DT1, 'DMY');
COMPUTE DT3/A12 = DATETRAN(DT2,'(DMY)','(-dt)','EN',12,'A12');
BY COUNTRY
END
```

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

 Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005 IP
Platinum Member
 posted October 06, 2010 07:37 AM Hide Post
Francis, thanks, this 'kind of' works. It does give me the desired format, but:

You have a hardcoded timestamp '2010-09-01 00:00:00' as an argument for the HINPUT function. When I put in my report variable(FLD_DT) in the formula:

DT1/HYYMDS = HINPUT(20, FLD_DATE, 8, 'HYYMDS');

It tells me that I have an erroneous argument.
When I put single quotes around my variable, it then gives me 31-Dec-00.

The timestamps I have in the database are:

2010-09-01 00:00:00
2010-09-02 00:00:00
.
.
.
.
2010-09-30 00:00:00

It looks like the formula is not picking up my variable.

7.7.02
Windows
EXCEL, PDF, CSV, TEXT

 Posts: 106 | Registered: June 25, 2009 IP
Expert
 posted October 06, 2010 10:05 AM Hide Post
The HINPUT in the DEFINE is to create a database date-time field, since none of the sample databases have one. You wouldn't need to do that step as you already have database date-time fields (not "variables").

You should only have to do the two COMPUTE statements - one to retrieve the Date portion of a Date-Time field, and the second to transform the Date field to an alpha string in the output format you desire.

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

 Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005 IP
Platinum Member
 posted October 06, 2010 10:16 AM Hide Post
Awesome, works like a charm. Thanks for your help!

7.7.02
Windows
EXCEL, PDF, CSV, TEXT

 Posts: 106 | Registered: June 25, 2009 IP

Focal Point    Focal Point Forums    WebFOCUS/FOCUS Forum on Focal Point     Date conversion [Resolved]