Focal Point
Format DateTime as Date Character with "mm/dd/yyyy" format

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

July 18, 2013, 07:57 PM
Phil DeBusk
Format DateTime as Date Character with "mm/dd/yyyy" format
OK, is it really this involved to simply change a date format to an alpha-10 with "mm/dd/yyyy" format?
I simply need to write a text string representation of my date to a file with the above format.

Here's my current solution to this:

Without changing the master and using SQL Server as the source I start with a date/time field of HYYMDs.
Example using a simple Define:

DEFINE FILE XYZ
FDATE/MDYY = HDATE(MY_BIRTHDAY,'MDYY'); -* First convert date to mm/dd/yyy as date
ALPHA_DATE/A8=DATECVT(ADATE,'MDYY','A8MDYY'); -* Next convert to alpha 8 as mmddyyyy
ALPHA_DATE_FMT/A10 = EDIT(ALPHA_DATE,'99/99/9999'); -* Finally convert to alpha 10 using edit with mask
END

TABLE FILE XYZ
PRINT
MY_BIRTHDAY/HYYMDs 'UNTOUCHED'
FDATE/MDYY AS 'DATE_MM/DD/YYYY'
ALPHA_DATE/A8 AS 'ALPHA8'
ALPHA_DATE_FMT/A10 AS 'ALPHA10_MM/DD/YYYY'
END

So I get: (fields are stacked for viewing)
MY_BIRTHDAY
05/15/1974:00:00:00.000

DATE_MM/DD/YYYY
05/15/1974

ALPHA8
05151974

ALPHA10_MM/DD/YYYY
05/15/1974

Surely there's a better/quicker way to arrive at a text string date with "mm/dd/yyyy" format. Right?

This message has been edited. Last edited by: Phil DeBusk,


WebFOCUS 7.6
Windows, All Outputs
July 19, 2013, 12:44 AM
Francis Mariani
Try this - two steps:
COMPUTE DT1A/A8MDYY = HDATE(MY_BIRTHDAY, 'MDYY');
COMPUTE DT1B/A10 = EDIT(DT1A,'99/99/9999');



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
July 19, 2013, 07:31 PM
Vivian
Phil - You might want to look at the (almost) 1001 Ways to Work with Dates covering thru release 8.0.2 from Aviter, Inc.....nearly everything that you will ever need to know to manipulate dates is there.

Vivian

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


Vivian Perlmutter
Aviter, Inc.


WebFOCUS Keysheet Rel. 8.0.2
(Almost) 1001 Ways to Work with Dates thru Rel. 8.0.2
Focus since 1982
WebFOCUS since the beginning
Vivian@aviter.com

July 20, 2013, 05:54 AM
Alan B
There are so many different ways of manipulating dates, the 1001 way to work with dates has the answer and would have saved time and effort.

ALPHA_DATE_FMT/A10=HCNVRT(MY_BIRTHDAY,'(HMDYY)',20,'A10');



Alan.
WF 7.705/8.007
July 21, 2013, 07:43 PM
Marc97229
I'd use EDIT if you can:

http://geekswithblogs.net/BI4f...date-conversion.aspx


WebFOCUS 8.0.0.8, Windows 7
July 22, 2013, 04:00 AM
Alan B
quote:
I'd use EDIT if you can

Other than using EDIT within the techniques that Phil and Francis have already come up with, how would EDIT help?


Alan.
WF 7.705/8.007
July 22, 2013, 12:03 PM
DavSmith
Phil, to convert a Date format field into an ALPHA with component demarcations in one step, use FPRINT. Note that FPRINT will also do a conversion from YYMD to MDYY.

TABLE FILE CAR
PRINT CAR 
COMPUTE CURRENT_HMDYY/HYYMDs  = HGETC(8,'HYYMDs');
COMPUTE CURRENT_ALPHA/A10    = FPRINT(CURRENT_HMDYY,'HMDYY','A10');
END


Check it by adding "ON TABLE SAVE" and reviewing the output. Then,look at the save.ftm and you'll see that CURRENT_ALPHA is indeed stored in ALPHA format with the component slashes.

Lastly, I do have an old version of the book but, FPRINT isn't covered. I don't know if it's covered in the latest version ... hmmm ... maybe I should write a book titled "(Just About) a Thousand different ways to use FPRINT"!

(just kidding folks)

For more FPRINT, check this out:
Converting To Alpha - Topic

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



In FOCUS since 1985 - WF 8.009/8.104 Win 8 Outputs: ALL of 'em! Adapters: Sql Server Teradata Oracle
July 22, 2013, 05:51 PM
John W Price
FPRINT function was added to WebFocus in release 7.7.01. The newest version of the "Dates" book does include FPRINT.
It is not in the current version of the dates book, but thanks to a hint from Francis Mariani, I have added it to the next release (around Oct 2013).
a) REFSDATE/MDYY WITH SD_MDY1='04152006';             
b) REFHMDYY/HMDYYS WITH SD_MDY1 = HGETC(8,REFHMDYY) ; 
c) REFLDATE/A8MDYY WITH SD_MDY1 = '04152006 ;         
d) REF_S01/A10 = FPRINT(REFSDATE,'M.D.YY', 'A10');    
e) REF_S02/A16 = FPRINT(REFSDATE,'MtrDYY', 'A16');    
f) REF_S03/A24 = FPRINT(REFSDATE,'MtrDwrYY', 'A24');  
g) REF_S04/A30 = FPRINT(REFHMDYY,'HMDYYS', 'A30');    
h) REF_S05/A30 = FPRINT(REFHMDYY,'HYYMDS', 'A30');    
i) REF_S06/A30 = FPRINT(REFHMDYY,'HYYMTdS', 'A30');   
j) REF_S07/A30 = FPRINT(REFHMDYY,'HYYMTDs', 'A30');   
k) REF_S08/A16 = FPRINT(REFLDATE,'A8MTDYY', 'A16');   
l) REF_S09/A16 = FPRINT(REFLDATE,'A8MtDYY', 'A16');   
Results
(a)  Base Smart Date =  04/15/2006                  
(b)    Base DateTime =  06/03/2013 19:46:21         
(c) Legacy Base Date =  04/15/2006                  
                         1    1    2    2    3     
out-format    ....5....0....5....0....5....0   
(d)   M.D.YY =  04.15.2006                         
(e)   MtrDYY =  April 15, 2006                     
(f) MtrDwrYY =  April 15 2006, Saturday            
(g)   HMDYYS =  06/03/2013 19:46:21                
(h)   HYYMDS =  2013/06/03 19:46:21                
(i)  HYYMTdS =  2013 June  3 19:46:21              
(j)  HYYMTDs =  2013 June 03 19:46:21.299          
(k)    MTDYY =  APR 15 2006                        
(l)    MtDYY =  APR 15 2006     
  




WebFOCUS 8.0.2, FOCUS since 1977 - John@Aviter.com
PDF , Excel, FOCUS, Author of the Keysheets and Dates book.
www.Aviter.com
July 23, 2013, 08:56 AM
DavSmith
That's good news John. Thanks! The book is truly useful. I have the first printing of the 2nd edition, dated 2006 so, it's probably time to get the "newest" version when it comes out in October.

BTW, FPRINT was added to official cannon in 7.7.01 but was added to 7.6.x as an undocumented feature...not sure which version it was added to but it works in our 7.6.11 environment.



In FOCUS since 1985 - WF 8.009/8.104 Win 8 Outputs: ALL of 'em! Adapters: Sql Server Teradata Oracle
July 23, 2013, 04:35 PM
John W Price
Thanks for the feedback. I will update the Keysheet and the dates books to reflect this. For now I'll just call it 7.6.11.



WebFOCUS 8.0.2, FOCUS since 1977 - John@Aviter.com
PDF , Excel, FOCUS, Author of the Keysheets and Dates book.
www.Aviter.com