Page 1 of 1

TIme calulation

Posted: Fri Jun 11, 2004 2:17 am
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...

Posted: Fri Jun 11, 2004 2:24 am
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

Posted: Fri Jun 11, 2004 2:31 am
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

Posted: Fri Jun 11, 2004 2:49 am
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

Posted: Fri Jun 11, 2004 6:52 am
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.

Posted: Fri Jun 11, 2004 7:07 pm
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!

Posted: Sat Jun 12, 2004 3:30 am
by mandyli
please try timedate() function..

Posted: Sat Jun 12, 2004 6:50 pm
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:")