Solved

Convert Systime to seconds

Posted on 2006-10-19
8
488 Views
Last Modified: 2010-04-05
Hi,

I need to do a calculation in my Select statement. The calculation is
((((1 + sysdate() - "job-dt-start") * 86400) +
         systime() - "job-tm-start" - 86400) / 86400)

in the above my job-tm-start is the time, its in  integer and stored as seconds.
but the systime is in HH:MM:SS format.  how to convert it to seconds.

Thanks
0
Comment
Question by:saroren
8 Comments
 
LVL 28

Expert Comment

by:TName
Comment Utility
Do you mean something like this (get the system time and multiply it's hour and minute component corespondingly)?:

procedure TForm1.Button1Click(Sender: TObject);
var
SysTime:TSystemTime;
sec:Integer;
begin
   GetLocalTime(sysTime);
   sec:=sysTime.wHour*3600+sysTime.wMinute*60+sysTime.wSecond;
   ShowMessage(IntToStr(sec));
end;
0
 

Author Comment

by:saroren
Comment Utility
No, I should be able to use it in the SQL statement.

select  "job-currop" ,"job-dt-start", "job-tm-start", systime,
((((1 + sysdate() - "job-dt-start") * 86400) +
     systime() - "job-tm-start" - 86400) / 86400)

from pub.job  where "act-ship" is null  

I am not able to do the above since the Systime is in the format  of "HH:MM:SS" and my job-tm-start has time stored in seconds (integer).


Thanks
0
 

Author Comment

by:saroren
Comment Utility
Any help Please!!!!
0
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
well that is not  adelphi quesiton but an sql question.
the following should help though I am not exactly sure if extract is supported in every DB server:

select  "job-currop" ,"job-dt-start", "job-tm-start", systime,
((((1 + sysdate() - "job-dt-start") * 86400) +
     extract (hour from systime())*3600+extract(minute from systime())*60+extract(second from systime()) - "job-tm-start" - 86400) / 86400)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:ewilde
Comment Utility

which SQL server are  you  connect to?
what do you mean by stored as integer? do you mean that 1AM=3600?
in general, schematicly, maybe you should do:

cast(substring(systime,1,2) as integer)*3600
+ cast(substring(systime,4,2) as integer)*60
+ cast(substring(systime,7,2) as integer)


i'm not sure i anderstand your question...
regards,
ewilde.
0
 

Author Comment

by:saroren
Comment Utility
I am using Progress Database

Hi Ciuly,

If i use the extract command it give me syntax error. So i guess its not supported.  is there any other way.
But thanks for your help

Hi Ewilde,

The current time is stored in a database field. the field is a integer format.
eg 12:45:13 is stored as 45913
 
you are right 01:00:00 AM is stored as 3600

I tried using your syntax it give an error "Inconsistent types"

so i just tried substring(systime,1,2)  still i have the same error.

Thanks
0
 
LVL 3

Accepted Solution

by:
cobi100 earned 500 total points
Comment Utility
well I'm not sure what you're trying to accomplish, but to convert the systime into seconds, I think you can use second, minute and hour, so try this:


select  "job-currop" ,"job-dt-start", "job-tm-start", systime,
((((1 + sysdate() - "job-dt-start") * 86400) +
     (hour(systime())*3600+minute(systime())*60+second(systime())) - "job-tm-start" - 86400) / 86400)
0
 

Author Comment

by:saroren
Comment Utility
Thanks cobi100,

Your solution worked.  
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now