TIme calulation

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
p.thier1
Participant
Posts: 10
Joined: Wed Jun 09, 2004 7:26 am

TIme calulation

Post by p.thier1 »

When I launch a job, i save the startdate and starttime in order
to write them later in a file.
I use the DSJobStartDate and DSJobStartTime functions (I can't find them
in the documentation !!!, maybe can you give me any link).

What I want to do is to make time calculation
If the current time is 10:25:29, i want to have in my result 10:25:29 - 5 seconds for example, so 10:29:24

Mydelayedtime = DSJobStartTime - 5 seconds

is there any functions to make this easily...

Thank you for your response...
denzilsyb
Participant
Posts: 186
Joined: Mon Sep 22, 2003 7:38 am
Location: South Africa
Contact:

Post by denzilsyb »

Try using Iconv to get the time to an internal format, do the calculation and then Oconv the value to the format you need.

the help details iconv/oconv quite well.

dnzl
dnzl
"what the thinker thinks, the prover proves" - Robert Anton Wilson
p.thier1
Participant
Posts: 10
Joined: Wed Jun 09, 2004 7:26 am

Post by p.thier1 »

denzilsyb wrote:Try using Iconv to get the time to an internal format, do the calculation and then Oconv the value to the format you need.

the help details iconv/oconv quite well.

dnzl
Yes I knew that these functions were useful, but I wanted to if there
were other functions

I will use them

Thanks
anupam
Participant
Posts: 172
Joined: Fri Apr 04, 2003 10:51 pm
Location: India

Post by anupam »

Alternatively, You can convert the time into seconds.
For eg you have Time in HH:MI:SS format
In Seconds = HH*60*60 + MI*60 +SS

and then substract 5 from Time in Seconds and then again convert it to the standard format you need.

I would not say that this approach is good but it is an alternative if u don't want to use Iconv/OconV
----------------
Rgds,
Anupam
----------------
The future is not something we enter. The future is something we create.
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

if you

X = iconv("12:00:01am", "MTHS")

then X should be 1. Internal version of time, I think, is seconds past midnight. The help on iconv() and MT conversion is very good. You can leave off the "am" and "pm". You can deal with 24 clocks whatever you need. Anything less than a second you should deal with yourself. My suggestion is leave the metadata as a varchar and iconv only when you need to add or subtract time.
Mamu Kim
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Eons ago I posted a function to calculate the interval between two timestamps. Search for it. If you can't find it I'll try to dig it out of my archives!
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
mandyli
Premium Member
Premium Member
Posts: 898
Joined: Wed May 26, 2004 10:45 pm
Location: Chicago

Post by mandyli »

please try timedate() function..
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

TIMEDATE() function returns the current date and time in a non-standard "timestamp-like" format.

The documented way to retrieve the job start is to use DSGetJobInfo with an InfoType argument of DSJ.JOBSTARTTIMESTAMP. The time component is in external format; you can retrieve it with substring or Field() function or the DataStage macro DSJobStartTime, then apply an Iconv() function to get it into internal format.

Kim's recollection is correct, in that internal format is seconds since midnight.

Therefore a suitable piece of code is the following.

Code: Select all

$IFNDEF JOBCONTROL.H
$INCLUDE DSINCLUDE JOBCONTROL.G
$ENDIF
JobStartTime = Iconv(DSJobStartTime, "MT")
FiveSecondsEarlier = JobStartTime - 5
If FiveSecondsEarlier < 0 Then FiveSecondsEarlier += 86400
If you need an expression it would be less efficient, because you have to evaluate the macro more than once. For example:

Code: Select all

If DSJobStartTime < "00:00:05" Then DSJobStartTime + 86395 Else DSJobStartTime - 5
but you could always create a stage variable (say svJobStartTime, initialized as the macro DSJobStartTime, and derived as not changing its value), so that the macro is only evaluated once for the entire job:

Code: Select all

If svJobStartTime < "00:00:05" Then svJobStartTime + 86395 Else svJobStartTime - 5
Finally, use Oconv() to get the time into a human-readable format, if that is desired.

Code: Select all

Oconv(FiveSecondsEarlier, "MTS:")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply