converting date + time into timestamp
750 pts.
0
Q:
converting date + time into timestamp
Hi I'm trying to convert date+time into timestamp n get thousands of error...

my code is as below

c     FMTIMCHAR     ifeq      '*ALL'

Eval      FMTIMCHAR = '0000'

C                   Eval      T1 = %subst(fmTIMCHAR:1:2) + ':' +  C                             %subst(fmTIMCHAR:3:2)              

C                   Eval      FMTMS1 = %Timestamp(%Char(FMDAT) + '-' + C                             T1 + '.000000')                         

 

above code errors out on compilation when T1 is declared as 4A(Character length 4) says...operand is too small to create a Timestamp

so I appended extra zero and passed values as

FMDAT = '2009-10-27'

T1 = '00:00:00'

now i get error Date, Time or Timestamp value is not valid. on %timestamp statement.

Please help



Software/Hardware used:
AS400
ASKED: Oct 27 2009  4:17 PM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
3250 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
This is a subprocedure I wrote sometime back. You should be able to modify it to suite your needs.


****************************************************************
* SET COMPILER OPTIONS *
****************************************************************
HNOMAIN
HOPTION(*NODEBUGIO:*SRCSTMT)
**********************************************************************
* PROGRAM NAME: CRTTIMSTMP *
* CREATION DATE: 04/20/04 *
* PURPOSE OF PROGRAM: CREATE DATE TIME STAMP. *
*********************************************************************
* PROTOTYPE FOR PROCEDURE.
*********************************************************************
D CRTTIMSTMP PR Z
D PASSDATE 8 0
D PASSTIME 4 0
D PASSTIME6 6 0
*********************************************************************
* START PROCEDURE DEFINITION.
*********************************************************************
P CRTTIMSTMP B EXPORT
D CRTTIMSTMP PI Z
D PASSDATE 8 0
D PASSTIME 4 0
D PASSTIME6 6 0
*********************************************************************
* DATE AND TIME FIELDS.
*********************************************************************
D RETURNSTAMP S Z INZ(*SYS)
D TIMESTAMP S T INZ(*SYS)
D DATESTAMP S D DATFMT(*ISO)
*********************************************************************
* FIELD DEFINITIONS.
*********************************************************************
D TIME6 S 6 0
D TIMCONVERT S 26 INZ('0001-01-01-00.00.00.000000')
D TIMEFLDC S 8 INZ
*********************************************************************
* FORMAT TIME AND DATE FIELDS.
*********************************************************************
C IF PASSTIME <> 0
C MOVEL PASSTIME TIME6
C ELSE
C MOVEL PASSTIME6 TIME6
C ENDIF

C MOVEL TIME6 TIMESTAMP
C MOVEL PASSDATE DATESTAMP
C MOVE TIMESTAMP TIMEFLDC
*********************************************************************
* CREATE DATE TIME STAMP.
*********************************************************************
C MOVEL DATESTAMP TIMCONVERT
C EVAL TIMCONVERT = %REPLACE(TIMEFLDC :
C TIMCONVERT : 12 : 8)
C MOVEL TIMCONVERT RETURNSTAMP
*********************************************************************
* RETURN DATE TIME STAMP.
*********************************************************************
C RETURN RETURNSTAMP

P CRTTIMSTMP E

Last Answered: Oct 27 2009  4:47 PM GMT by Teandy   3250 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Nutangujar   750 pts.  |   Oct 27 2009  4:54PM GMT

yippee
i think i got the answer…in the time field instead of ‘:’ i shud use ‘.’
silly mistake….

thanks guys…

 

Satsho   1235 pts.  |   Oct 27 2009  7:44PM GMT

You can always use the Convert Date and Time Format (QWCCVTDT) API

 

TomLiotta   7990 pts.  |   Oct 27 2009  8:32PM GMT

IMO — Note that the date/time format for the program should be set explicitly. The default is generally *ISO, but could be changed. If the DATFMT() control spec is explicit, your program code can then be able to use the same date/time separators under all circumstances. Choose a standard format for handling inside the program. Be aware that system and job formats might change at any time. With a program format set, conversions can always be standardized in code.

Tom

 
0