converting date + time into timestamp

895 pts.
Tags:
AS/400 date format
Date calculation
RPGLE Date Calculation
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

Answer Wiki

Thanks. We'll let you know when a new response is added.

This is a subprocedure I wrote sometime back. You should be able to modify it to suite your needs.

<pre>
****************************************************************
* 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

</pre>

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Nutangujar
    yippee i think i got the answer...in the time field instead of ':' i shud use '.' silly mistake.... thanks guys...
    895 pointsBadges:
    report
  • Satsho
    You can always use the Convert Date and Time Format (QWCCVTDT) API
    1,245 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following