Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Difference between two datetime values

2,943 views
Skip to first unread message

Paul Murray

unread,
Feb 27, 2008, 8:21:16 PM2/27/08
to
Maybe I have been hit by the stupid stick, but I am having trouble with
figuring out how to code in order to see if two datetime values are less
than one hour apart or not.

The DaysAfter function works fine if the the two dates are at least one day
apart.

But SecondsAfter doesn't do a lot of good if there is a date rollover.

For example, datetime1 is 02/27/2008 23:45:00 and datetime2 is 02/28/2008
00:15:00. A simple powerbuilder built-in function as
datetimediff(date1,date2) should give me 1,800 seconds. But subtracting the
dates gives me -1 and subtracting the times gives me -84600.

My head spinneth!!

Can someone help me? I expect that this is easy, but my brain does not
function well with date roll overs!

Note to Sybase: A built-in function to handle this and other datetime
related functions would be nice.

I have this nice function that gajender_99 helped out with at
experts-exchange.com.

Give it a date, a time horizon in hours and it gives you the end datetime
(AND HANDLES THE MIDNIGHT ROLLOVER). This is all quite arcane. Everyone
needs to do this stuff. Why does not Sybase make it easy to do!?

datetime start_pickupdatetime,end_pickupdatetime
date vl_today
time vl_now

long horizon,vl_hour,vl_min,vl_ss
string vl_time
horizon = long(ddlb_horizon.text)
vl_now=now()
vl_today=today()
vl_min=minute(vl_now)
vl_hour=hour(vl_now)
vl_ss=second(vl_now)
vl_hour=vl_hour + horizon
if vl_hour>=24 then
vl_hour=vl_hour - 24
vl_today=relativedate(vl_today,1)
vl_time=string(vl_hour)+':'+string(vl_min)+':'+string(vl_ss)
end_pickupdatetime = DATETIME(vl_today,time(vl_time))
Else
vl_time=string(vl_hour)+':'+string(vl_min)+':'+string(vl_ss)
end_pickupdatetime = DATETIME(vl_today,time(vl_time))

End if
//horizon = long(ddlb_horizon.text) * 60 * 60
messagebox("horizon is",string(horizon))
start_pickupdatetime = DATETIME(today(), vl_now)

dw_1.retrieve(start_pickupdatetime,end_pickupdatetime)


Goose

unread,
Feb 27, 2008, 8:43:52 PM2/27/08
to
Sorry, I am not helping.
Is there is function like the "System.currentTimeMillis()" in JAVA which
return the total time millisecond (1/1000 of a second) since a specific
time?
If there is, you may solve you problem by substract the two millis.
e.g.

long a = currentTimeMillis()
....
long b = currentTimeMillis()

totalSecond = (b-a) / 1000
totalMinute = (b-a)/1000/60

++OIL

"Paul Murray" <pemu...@staysystems.com> 撰寫於郵件新聞:47c60c8c$1@forums-1-dub...

Daniel Jenkins

unread,
Feb 28, 2008, 2:12:12 AM2/28/08
to Paul Murray
I've been using this code (probably found it on these newsgroups):

ll_hours = DaysAfter (date (ldt_1), date (ldt_2)) * 24.0 + SecondsAfter
(time (ldt_1), time (ldt_2)) / 3600.0 + .5

HTH

Daniel.

Goose

unread,
Feb 28, 2008, 3:30:47 AM2/28/08
to
so it seems you have solve the problem...
++OIL
Thanks


"Daniel Jenkins" <danieldotje...@gacnospamworld.com>
???????:47C65F0F...@gacnospamworld.com...

Ken Balakrishnan

unread,
Feb 28, 2008, 8:58:12 AM2/28/08
to
PMFJI, and sorry if I'm being dense, but why does the formula add .5 at the
end?

Ken

"Daniel Jenkins" <danieldotje...@gacnospamworld.com> wrote in
message news:47C65F0F...@gacnospamworld.com...

Paul Murray

unread,
Feb 28, 2008, 9:29:42 AM2/28/08
to
Oh, thank you!!

Daniel, I had to take off the '+ .5' at the end of the calculation, but it
works perfectly. I defined ll_hours as decimal. I guess you were giving it
a 30 minute buffer.

Again, my most sincere thanks!!

Goose, thanks for diving in as well.

Paul


"Daniel Jenkins" <danieldotje...@gacnospamworld.com> wrote in
message news:47C65F0F...@gacnospamworld.com...

0 new messages