Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Convert Systime to seconds

Posted on 2006-10-19
8
491 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
ID: 17767517
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
ID: 17767572
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
ID: 17768245
Any help Please!!!!
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 28

Expert Comment

by:2266180
ID: 17768621
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
 
LVL 5

Expert Comment

by:ewilde
ID: 17768805

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
ID: 17769289
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
ID: 17769740
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
ID: 17769862
Thanks cobi100,

Your solution worked.  
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Newbie Thread Programming 1 161
Printing problem 2 101
IdTCPClient and IdTCPServer exchanging data on desktops and not Android 11 140
Delphi: making a BW image transparent 10 57
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 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