5 pts.
 How do I parse out a timestamp ISO format into a date field
How do I parse out a timestamp ISO format into a date field? This is how the field looks: Timestamp ISO Format 2008-10-08-12.13.52.412000 Here is the description of the field: Field From To Length Type Description XXXXXXX 57 82 0 Z Timestamp ISO Format I need to get the 2008-10-08 into a date format so that I can match it and pull in specific dates only. Thank you.

Software/Hardware used:
ASKED: October 21, 2008  5:20 PM
UPDATED: September 4, 2010  4:02 AM

Answer Wiki:
In RPG it would be something like this DateFld = %date(%subst(%char(TimeStamp):1:10):*ISO) In Query, you should just be able to substring the 1st 10 chars
Last Wiki Answer Submitted:  October 22, 2008  11:56 am  by  graybeard52   3,115 pts.
All Answer Wiki Contributors:  graybeard52   3,115 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

It the date field is a true date field – type D – then just move the timestamp field to the date field and it will work correctly.

 1,410 pts.

 

There is also the BIF called %subdt. For instance in your case to extract the date you have

yy = %subdt(timestamp:*y)

 45 pts.

 

…to extract the date…

The %subdt() BIF does not extract a date from a timestamp field. It can extract a component of a date such as the year or the month. To get a full “date”, it would be necessary to extract the three year/month/day components and combine the three results into the required form.

As Vatchy suggested, simply assigning the timestamp value to a DATE field would be much cleaner.

Tom

 108,045 pts.

 

In cobol, if the from and to dates are defined as date formats TIMESTAMP and YYYY-MM-DD respectively, then it’s just a simple move statement.

 880 pts.

 

Tom is right, %subdt can get parts of a date.
%date( ) can work with numeric, character or timestamp fields
D Dateval D (default is ISO
dateval = %date(timestamp)

dateval is a date field
YYMMDD= #CHAR(dateval:*YMD0) 100903 character
YYMMDD= #CHAR(dateval:*YMD) 10/09/03 Character
YYMMDD#= %DEC(%CHAR(dateval:*YMD):*YMD0)) 100903 numeric

Good Luck
PGMBOB

 695 pts.