Time conversion

Archive of postings to DataStageUsers@Oliver.com. This forum intended only as a reference and cannot be posted to.

Moderators: chulett, rschirm

Locked
admin
Posts: 8720
Joined: Sun Jan 12, 2003 11:26 pm

Time conversion

Post by admin »

Hello,

I am not a good universe basic writer but I am just wondering if anybody has developed such a routine before that convert a specific time format into another format.

What my requirement is to convert a time format HH:MMam/pm to HHMM.

For example,
1) 9:34am to 934
2) 9:34pm to 2134
3) 12:12am to 0012

Is there an existing Datastage function that can do this kind of time conversion?

Cheers,
Paul.
admin
Posts: 8720
Joined: Sun Jan 12, 2003 11:26 pm

Post by admin »

Oconv(string, "MCN")

"MCN" is "masked character numeric", which removes all non-numeric characters from the string.

-----Original Message-----
From: Paul Ko [mailto:PKO@clear.co.nz]
Sent: Friday, 21 September 2001 09:02
To: datastage-users@oliver.com
Subject: Time conversion


Hello,

I am not a good universe basic writer but I am just wondering if anybody has developed such a routine before that convert a specific time format into another format.

What my requirement is to convert a time format HH:MMam/pm to HHMM.

For example,
1) 9:34am to 934
2) 9:34pm to 2134
3) 12:12am to 0012

Is there an existing Datastage function that can do this kind of time conversion?

Cheers,
Paul.
admin
Posts: 8720
Joined: Sun Jan 12, 2003 11:26 pm

Post by admin »

Paul, checkout the BASIC .pdf file that is under the
DataStage documentation on your Start button -->
Ardent DataStage -->Online Manuals --> Universe
documentation.

There are two functions called ICONV and OCONV with
which you want to become familiar. ICONV can be
handed a time and format string and it will turn it
into the integer number of seconds since midnight.
OCONV can be used to format the integer number of
seconds since midnight into any timestamp format you
desire. Using these two BASIC functions in a
DataStage user defined function can do pretty much any
tricks you desire.

Also, learn the TRIM, FIELD, CONVERT, CHANGE, COUNT,
and INDEX functions/statements. You will use these
90% of the time in any custom transformation function
you wish to write. You can use these to build a
custom library of routines that are modular and can be
used throughout your job designs to simplify your
coding experience.

One function I cant do without is one I call Exists.
The code is simply:

x=TRIM(Arg1)
If ISNULL(x) OR X= Then
Ans = @FALSE
End Else
Ans = @TRUE
End

I use this function to test for the existence of a
value, and in a constraint its easy to use. Youll
have to develop a few of these to solve your custom
time formats. Ive got a library of my own you can
have if youre interested. Send me an email if youre interested.

Good luck!
-Ken





--- Paul Ko wrote:
> Hello,
>
> I am not a good universe basic writer but I am just
> wondering if anybody has
> developed such a routine before that convert a
> specific time format into
> another format.
>
> What my requirement is to convert a time format
> HH:MMam/pm to HHMM.
>
> For example,
> 1) 9:34am to 934
> 2) 9:34pm to 2134
> 3) 12:12am to 0012
>
> Is there an existing Datastage function that can do
> this kind of time
> conversion?
>
> Cheers,
> Paul.
>


__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information http://dailynews.yahoo.com/fc/US/Emergency_Information/
admin
Posts: 8720
Joined: Sun Jan 12, 2003 11:26 pm

Post by admin »

Paul,

The following might get you started on how to do this. Since there is not
a direct way using ICONV / OCONV to generate your end result, a little bit
of data massaging has to be done. Here, we have the three strings A, B and
C (lines 1 thru 3). Lines 4 thru 6 convert these external format times
into internal times (in seconds). Lines 7 thru 9 externally convert those
internal numbers to 24 hour format (MT), and the result of that conversion
passed to TRIM, which removes all (A) occurrences of the colon. This could
be compacted down further by embedding the appropriate ICONV within the
OCONV, i.e. TRIM(OCONV(ICONV(A,"MT"),"MT"),":","A").

TEST
0001 A="9:34AM"
0002 B="9:34PM"
0003 C="12:12AM"
0004 AA= ICONV(A,"MT")
0005 BB= ICONV(B,"MT")
0006 CC= ICONV(C,"MT")
0007 PRINT TRIM(OCONV(AA,"MT"),":","A")
0008 PRINT TRIM(OCONV(BB,"MT"),":","A")
0009 PRINT TRIM(OCONV(CC,"MT"),":","A")

When run this program generates:
>RUN BP TEST
0934
2134
0012

Hope this helps.
Glenn

At 07:01 PM 9/20/01, you wrote:
>Hello,
>
>I am not a good universe basic writer but I am just wondering if
>anybody has developed such a routine before that convert a specific
>time format into another format.
>
>What my requirement is to convert a time format HH:MMam/pm to HHMM.
>
>For example,
>1) 9:34am to 934
>2) 9:34pm to 2134
>3) 12:12am to 0012
>
>Is there an existing Datastage function that can do this kind of time
>conversion?
>
>Cheers,
>Paul.
Locked