Difference between times

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
swapnilverma
Participant
Posts: 135
Joined: Tue Aug 14, 2007 4:27 am
Location: Mumbai

Difference between times

Post by swapnilverma »

Hi

Can anyone please tell me , is there any function or any way by which I can get the difference between two times.

i.e.

Column Type

A Time
B Time

A-B = Diff in seconds

Please note that the field type is Time,I found a function which takes Timestamp as input . SecondsSinceFromTimestamp


Thanks
Thanks
Swapnil

"Whenever you find whole world against you just turn around and Lead the world"
satya_y4u
Participant
Posts: 2
Joined: Tue Dec 04, 2007 10:54 am

Post by satya_y4u »

u have two funtions to find the diffrence two dates in the transformer

1 is juilansday fromdate

ex:u have two columns ..a and b

put in the transformer :..juilandatefromdae(a)-juliandatefromdate(b)

i think u get the result
satya_y4u
Participant
Posts: 2
Joined: Tue Dec 04, 2007 10:54 am

Post by satya_y4u »

u have two funtions to find the diffrence two dates in the transformer

1 is juilansday fromdate

ex:u have two columns ..a and b

put in the transformer :..juilandatefromdae(a)-juliandatefromdate(b)

i think u get the result
ZDC
Premium Member
Premium Member
Posts: 15
Joined: Fri Nov 23, 2007 5:06 am

Post by ZDC »

Hi there,

If you have two time columns like 20:20:20 as HH:MM:SS

then i think it can be done this way,

use hoursfromtime,minutesfromtime and secondsfromtime function in variables,
get the difference between two columns in variables in hours,minutes and seconds.

multiply diff in hr by 3600,min by 60 ,sec as it is.

add these and you will get the difference in seconds.

i havent tried it but i think it should work.

cheers,
ZDC
Zero Degree Consulting
Maveric
Participant
Posts: 388
Joined: Tue Mar 13, 2007 1:28 am

Post by Maveric »

Look at the function SecondsFromTime(%time%). Read the documentation for it. SecondsFromTime(A) - SecondsFromTime(B) should work.
swapnilverma
Participant
Posts: 135
Joined: Tue Aug 14, 2007 4:27 am
Location: Mumbai

Post by swapnilverma »

Thanks

I had thought of this....the problem comes when the time First is 23:59:58
and the second one is 00:00:00.

The calcuations would go for a toss....ideally it should come as 2 seconds.

since I donot have the date........its just time,it causes problems.

I have to track a 2 second difference between the two times.

I tried iconv too.....but the problem persits

Can you please suggest anything on this

ZDC wrote:Hi there,

If you have two time columns like 20:20:20 as HH:MM:SS

then i think it can be done this way,

use hoursfromtime,minutesfromtime and secondsfromtime function in variables,
get the difference between two columns in variables in hours,minutes and seconds.

multiply diff in hr by 3600,min by 60 ,sec as it is.

add these and you will get the difference in seconds.

i havent tried it but i think it should work.

cheers,
ZDC
Thanks
Swapnil

"Whenever you find whole world against you just turn around and Lead the world"
swapnilverma
Participant
Posts: 135
Joined: Tue Aug 14, 2007 4:27 am
Location: Mumbai

Post by swapnilverma »

I guess these would only take second's part

I have a scenario

the time First is 23:59:59
and the second one is 00:00:01.

Ideally the difference should be 2 seconds.
Would these work.

or some with time 23:55:22 and 23:59:24




Maveric wrote:Look at the function SecondsFromTime(%time%). Read the documentation for it. SecondsFromTime(A) - SecondsFromTime(B) should work.
Thanks
Swapnil

"Whenever you find whole world against you just turn around and Lead the world"
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Perhaps something as simple as 'hard-coding' two dates one day apart onto the front of the times to create complete timestamps to compare?
-craig

"You can never have too many knives" -- Logan Nine Fingers
ZDC
Premium Member
Premium Member
Posts: 15
Joined: Fri Nov 23, 2007 5:06 am

Post by ZDC »

Hi ,

while using hoursfromtime function if hours from Time 1 is greater than hours from Time 2 just add 24 to the time 2 hrs and then do the calculations.

eg.

Time 1 - 23:59:59
Time 2 - 00:00:01

if hoursfromtime(Time 1)>hoursfromtime(Time 2) then {hoursfromtime(time2)+24} else hoursfromtime.

so output will be (24-23)*3600+(0-59)*60+(1-59)

do this in stagevariable ,it will solve your problem.

Cheers,
ZDC
Zero Degree Consulting
Post Reply