Convert Seconds to Hours:Minutes:Seconds
If I have an integer holding the number of seconds, how can I convert it into a string/relavant format in the form Hours:Minuteseconds?
For example, 123 seconds should be 00:02:03.
If it is possible to do the above, then how can I seperate it into 00 Hours indicator, 02 Minutes indicator and 03 Seconds indicator?
Here are some alternative solutions, there are many more. (VI is LabVIEW 8.2)
LabVIEW Champion . Do more with less code and in less time .
Attachments:
GetTimeElements.png 31 KB
GetTimeElements.vi 11 KB
Similar Messages
-
How to convert frames into hours:minutes:seconds?
if I have some columns which contains the time value in frames, i.e. Content_Duration, program_duration etc.
How can I convert those frames in hh:mm:ss?
Is it possible to do it with a function do that so that I can re-use it?
ThanksI am not quite sure where you get content_interval from?CONTENT_INTERVAL comes from the function call "numtodsinterval( content_duration / 1500, 'MINUTE' )" in the inline view.
You might want to code it as "numtodsinterval( content_duration / 25, 'SECOND' )" to match the 25 frames/second standard you mentioned after I posted my reply.
will it allow more than 99 hours? i.e. 154:57:40?Actually, it won't work for more than 23 hours, 59 minutes, 59 seconds. For larger numbers this technique requires a field for the number of days, like this.
SQL*Plus: Release 10.2.0.1.0 - Production on Fri Jun 29 12:41:38 2007
create table t ( content_duration number );
Table created.
insert into t values ( 1500*60*99 /* = 99 hours */ );
1 row created.
commit;
Commit complete.
select
lpad(extract(DAY from content_interval),2,'0')||' '||
lpad(extract(HOUR from content_interval),2,'0')||':'||
lpad(extract(MINUTE from content_interval),2,'0')||':'||
lpad(extract(SECOND from content_interval),2,'0')
as result
from
( select numtodsinterval( content_duration / 25, 'SECOND' ) as content_interval
from t
RESULT
04 03:00:00
1 row selected.
-- if you're going to show DAYS though, the following way is simpler
select
cast
( numtodsinterval( content_duration / 25, 'SECOND' ) as interval day(2) to second(0))
as result
from t ;
RESULT
+04 03:00:00
1 row selected.If you really need output like 99:00:00 instead of +04 03:00:00 then take Volder's approach.
Is it possible to do it as a function?Anything you can do with a SQL query you can probably do inside a function, but for a line of code like "cast ( numtodsinterval( ..." I personally wouldn't bother.
Joe Fuda
SQL Snippets -
Convert Format Day, Hour, Minute, Seconds in Hours
Hi all,
I have one report generate by VoIP application like this:
Total of hour has showed in Day (4). hour (20): Minute (26): seconds (06) summarize 4.20:26:06
I need convert this format only how like 116 (hours) 26 (twenty six) Minutes 06 (Six) seconds. summarize 116:26:06
How I can make this?
Regards!
Douglas Filipe http://douglasfilipe.wordpress.comHi,
I'm marking the reply as answer as there has been no update for a couple of days.
If you come back to find it doesn't work for you, please reply to us and unmark the answer.
Thanks
George Zhao
Forum Support
Come back and mark the replies as answers if they help and unmark them if they provide no help.
If you have any feedback on our support, please click "[email protected]" -
FM for microseconds to hours : minutes : seconds : microseconds conversion
Hi Expart ,
Is there is any Fm to Convert microseconds to hours : minutes : seconds : microseconds. Actually i get the runtime in Micro second and i need to display it in above format .
Please help me to get the fm or other simple way to do this
Thanks
RajuHi,
Use this link
FM to converts seconds into HH:MM:SS
Function Module for converting seconds into hours and minutes
Hope these will help you.
Regards,
Vijay -
Showing a measure as days/hours/minutes
Hi gurus, I need you help quickly:)
I have a report that shows duration of time for certain actions. The only measure in the report is hours (with two decimals). I want the measure to be shown as e.g. 4 days, 4 hours, 30 minutes instead of 100,5 (hours). Is this possible. Sorry if the question is noobThank you very much! Works just as it should!:)
EDIT: Realized that my measure was MINUTES, not HOURS ...
But that´s good cause editing the formula provided by Sandeep forced me into really understanding it:)
If it helps anyone, here´s what you put in the column formula if you want number of MINUTES converted to days, hours, minutes:
cast(floor(column_name/1440) as char)||'days'||' '||cast(floor(mod(column_name,1440)/60) as char)||'hours'||' '||cast(mod(mod(column_name,1440),60) as char)||'minutes'
Edited by: SJV4-ever on 2011-mar-16 08:42 -
Convert seconds to Days, hours, Minutes, Seconds in Reporting Services
Hi Guys,
Im currently reporting of an analysis services cube, however I have value which is in seconds and would like to report on this in reporting services as day:HH:MM:SS.
Has anyone got any experience reporting in this format?
Regards
DaveHi Dave,
We can use custom code to convert seconds to HH:MM:SS
Public Function Calculate(ByVal TotalSeconds as Integer) as String
Dim Hours, Minutes, Seconds As Integer
Dim Hour, Minute, Second As String
Hours = floor(TotalSeconds/ 3600)
IF Hours<10
Hour="0" & Hours.ToString
Else
Hour=Hours.ToString
End IF
Seconds = TotalSeconds Mod 3600
Minutes =floor( Seconds / 60)
IF Minutes<10
Minute="0" & Minutes.ToString
Else
Minute=Minutes.ToString
End IF
Seconds = Seconds Mod 60
IF Seconds<10
Second="0" & Seconds.ToString
Else
Second=Seconds.ToString
End IF
Return Hour & ":" & Minute & ":" & Second
End Function
Then we can use the expression to conver it.
=Code.Calculate(Fields!Column.Value)
The report looks like below:
If you have any questions, please feel free to ask.
Regards,
Charlie Liao
If you have any feedback on our support, please click
here.
Charlie Liao
TechNet Community Support -
I need help to convert hours,minutes and seconds to seconds.
Hi, I need help with the code on how to convert the hours,minutes and seconds to seconds. I don't know which formula to use so that I can get the results in total number of seconds. Thanks.
Jos ("when in doubt: parenthesize correctly")Bracist.You're more right than you'd known: last week I climbed over a safety
fence (which I wasn't supposed to do of course) to adjust the position
of an optical measurement device we installed in a huge production
machine in a factory. I stepped on some sort of hose; the end of that
hose broke loose and hit me straight in the middle of my lower jaw. My
front teeth feel wiggly now and my molars on the left of my lower jaw are
not what they used to be. This Wednesday I get that all fixed at some
dental clinic. Keep your fingers crossed because me+dentists == war.
My tongue continuously keeps on reporting craters and disaster ;-)
Jos, how's it going? Besides a possible loss of some teeth, I'm fine ;-)
My Spring/Hibernate journey continues. I'm trying out Hibernate 3.2
annotations and the Ant tools. So far, so good.Good to hear. At the moment I'm putting my teeth (sic) in that darn snmp
stuff which simply refuses to work the way I want it and besides that I'm
heavily involved in some of that SAP stuff. Spring is not in the vicinity for
me in the next couple of months sadly enough.
kind regards,
Jos -
Converting seconds to hours + minutes + seconds
hey all,
was just looking for the quickest way to convert seconds to hours + minutes + seconds
eg, 18084 s is 5h, 1m, 24s.You can use the Apache Commons Lang DurationFormatUtils class
import org.apache.commons.lang.time.*;
public class SecondsConversion {
public static void main(String[] args) {
try {
int seconds = 18084;
int milliseconds = seconds * 1000;
String[] values = DurationFormatUtils.formatDuration(milliseconds, "H m s").split(" ");
System.out.println(values[0] + "h " + values[1] + "m " + values[2] + "s ");
} catch (Exception e) {
e.printStackTrace();
} -
How do I log the time in hours, minutes and seconds to a table
Hi
I'm a relatively new user of Labview. I am currently writing a program that logs the temperature of an oven and the current time to a table and graph. I am using a GPIB card to communicate with the oven. I have used the Get Date/Time string to get the time and the Decimal String to Number to convert the time to a number which I have then put into an array which goes to a table and graph. My problem at the moment is that the time is being logged in hours only. I need to log the time in hours, minutes and seconds. Can you tell me how I can do this?Hi,
I can see the setup now. The decimal string to number will only ever give the hours, since the ':' character is not part of a number, so won't translate. Use the code I attached previously to get the time as a timestamp, and then go from there.
I've made some modifications, although you'll need to alter the file save to take into account the double precision number
for the timestamp is now 3E+9 (since it's seconds since 1904!!), but since you're writing to a comma separated values (or tab deliminated) style file, this shouldn't be a problem. You could always do a textual save from the table instead.
Thanks
Sacha Emery
National Instruments (UK)
// it takes almost no time to rate an answer
Attachments:
temp time program.vi 98 KB -
Write elapsed time to a spreadsheet in hours:minutes:seconds format
Hi everyone,
I've been trying to write an elapsed time to a spreadsheet file in an hours:minutes:seconds format, but the time is displayed in a floating point value of seconds..
how can I write to a spreadsheet in an hours:minutes:seconds format.
Thank you,
James-I often use a subVI that converts Seconds to Hours, Minutes and Seconds. Use the Quotient and Remainder function to divide your elapsed time by 3600, 60 and 1. You can then convert those values to a modified string and use the Write to Spreadsheet File.
As Dennis said, newer versions of LabVIEW's Write to Spreadsheet File.VI can handle arrays of Double, Integer or String automatically, and in older versions, the Write to Spreadsheet File.VI can be modified and copied to handle strings.
Hope this helps.
(Written in 8.5)
Message Edited by LabViewGuruWannabe on 01-18-2008 09:28 PM
Attachments:
TimeToSpreadsheet.vi 26 KB
SecondstoHMS.png 32 KB -
Date difference in Days,hours minutes and seconds.
Hi All,
I have two date Suppose one is getdate() and other one is gatedate() +1 .I have to show the difference, currently I used a datediff in the stored proc which just shows the difference of the days :( but i need to show the difference in days:hours:minutes:seconds if possible.
its a countdown with the current date. Like the two fields are sale_start_date and sale_end_date. Hope i am clear.
Please let me know ASAP thanks in advance.Can anyone help me?all help is great help.
Say the difference of
12/6/2007 7:00:00 AM, 12/8/2007 8:00:00 AM as 2 days 1:00:00)
Thanks
NOne of the problems of using DATEDIFF when dealing with either seconds or milliseconds is that this function will result in execution errors if the start and end dates span then entire domain of possible dates. Below is an alternative that seems to work over the entire date domain. A couple of things to note:
1. This select converts the days and seconds of each date into BIGINT datatypes to avoid the overflow error
2. This select uses a CROSS APPLY operator; in this case I chose CROSS APPLY to suggest the possibility of converting this select into an inline table function.
I suspect that if you dig around this forum and the net that you will find a better routine, but here is yet another alternative:
declare @test table
( startDate datetime, endDate datetime)
insert into @test values
('6/1/9', getdate()),
('6/9/9 15:15', '6/10/9 19:25:27.122'),
('6/9/9 15:15', '6/10/9 13:25:27.122'),
('6/9/9', '6/10/9 00:00:01'),
('1/1/1760', '12/31/2999')
select
startDate,
endDate,
[Days],
[Hours],
[Minutes],
[Seconds]
from @test
cross apply
( select
cast((endSecond - startSecond) / 86400 as integer) as [Days],
cast(((endSecond - startSecond) % 86400) / 3600 as tinyint) as [Hours],
cast(((endSecond - startSecond) % 3600) / 60 as tinyint) as [Minutes],
cast((endSecond - startSecond) % 60 as tinyint) as [Seconds]
from
( select
86400 * cast(convert(integer, convert(binary(4),
left(convert(binary(8), startDate),4))) as bigint)
+ cast(convert(integer, convert(binary(4),
right(convert(binary(8), startDate),4)))/300 as bigint)
as startSecond,
86400 * cast(convert(integer, convert(binary(4),
left(convert(binary(8), endDate),4))) as bigint)
+ cast(convert(integer, convert(binary(4),
right(convert(binary(8), endDate),4)))/300 as bigint)
as endSecond
) q
) p
/* -------- Sample Output: --------
startDate endDate Days Hours Minutes Seconds
2009-06-01 00:00:00.000 2009-06-22 08:28:36.670 21 8 28 36
2009-06-09 15:15:00.000 2009-06-10 19:25:27.123 1 4 10 27
2009-06-09 15:15:00.000 2009-06-10 13:25:27.123 0 22 10 27
2009-06-09 00:00:00.000 2009-06-10 00:00:01.000 1 0 0 1
1760-01-01 00:00:00.000 2999-12-31 00:00:00.000 452900 0 0 0
(5 row(s) affected)
EDIT:
I based the routine more-or-less on Thilla's reply.
Kent Waldrop -
Hi
I would like to convert seconds to hours -
I have tried the below two -
select to_char(to_date(176400,'SSSSS'),'HH:MI:SS') from dual;
SELECT NUMTODSINTERVAL (176400, 'minute') FROM DUAL;
RegardsHi,
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
Simplify the problem as much as possible. Remove all tables and columns that play no role in this problem.
Always say which version of Oracle you're using.
If you have a number of seconds (s), you can find the equivalent number of hours (h) if you divide s by the number of seconds in an hour, 60 * 60 = 3600.
SELECT s
, s / 3600 AS h
FROM table_x
;H won't necessarily be an integer. If you want an integer, use a rounding function: ROUND, TRUNC, FLOOR or CEIL -
Adding day/hour/minute/second to a date value
How does one add a day/hour/minute/second to a date value?
SQL> select to_char(sysdate, 'DD/MM/YYYY HH24:MI:SS') to_day,
2 to_char(sysdate+1, 'DD/MM/YYYY HH24:MI:SS') add_day,
3 to_char(sysdate + 1/24, 'DD/MM/YYYY HH24:MI:SS') add_hour,
4 to_char(sysdate + 1/(24*60), 'DD/MM/YYYY HH24:MI:SS') add_minute,
5 to_char(sysdate + 1/(24*60*60), 'DD/MM/YYYY HH24:MI:SS') add_second
6 from dual
7 /
TO_DAY ADD_DAY ADD_HOUR ADD_MINUTE ADD_SECOND
10/10/2006 11:54:23 11/10/2006 11:54:23 10/10/2006 12:54:23 10/10/2006 11:55:23 10/10/2006 11:54:24
SQL>Cheers
Sarma. -
How can i bring Hour,Minute, second info in RMAN log ?
DB version: 11.2.0.3
Platform : Oracle Enterprise Linux 6.2
Below is an excerpt from RMAN backup log file.
As shown with the arrows below, the RMAN backup log doesn't have Hour, Minute and Second information. It just has the date 14-OCT-13
input archived log thread=1 sequence=10946 RECID=21079 STAMP=828801629
input archived log thread=2 sequence=10137 RECID=21081 STAMP=828801794
input archived log thread=1 sequence=10947 RECID=21080 STAMP=828801731
channel ch01: starting piece 1 at 14-OCT-13 --------------------------------------------> We need Time here like 17:28:43
channel ch00: finished piece 1 at 14-OCT-13
piece handle=al_9306_1_828819222 tag=TAG20131014T190816 comment=API Version 2.0,MMS Version 5.0.0.0
channel ch00: backup set complete, elapsed time: 00:14:55
channel ch00: deleting archived log(s)
<snipped>
How can I implement the equivalent of below statement for RMAN logging ?
alter session set nls_date_format='DD-MM-YYYY HH24:MI:SS';HI,
Very interesting question. I think there is no difference. I did the test. There is no difference in terms of performance. But I'm always on the way RMAN Strategist
$ export NLS_DATE_FORMAT=’DD-MON-YY HH24:MI:SS’
$ echo $NLS_DATE_FORMAT
DD-MON-YY HH24:MI:SS
$
$ rman target / nocatalog
Recovery Manager: Release 10.2.0.5.0 – Production on Thu Jun 9 14:47:05 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved
connected to target database: ANARTEST (DBID=1459801106)
using target database control file instead of recovery catalog
RMAN> list backup of database completed between ‘sysdate-2′ and ‘sysdate’;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
1103 Full 591.40M DISK 00:04:38 08-JUN-11 01:04:43
BP Key: 1103 Status: AVAILABLE Compressed: YES Tag: TAG20110608T010004
Piece Name: /oracle/rman/dbbak/Daily_bak_1459801106_2mmeb0ol_1_1.bak
List of Datafiles in backup set 1103
File LV Type Ckp SCN Ckp Time Name
1 Full 33971595 08-JUN-11 01:00:05 /dba/data/system01.dbf
2 Full 33971595 08-JUN-11 01:00:05 /dba/data/undotbs01.dbf
3 Full 33971595 08-JUN-11 01:00:05 /dba/data/sysaux01.dbf
4 Full 33971595 08-JUN-11 01:00:05 /dba/data/users01.dbf
5 Full 33971595 08-JUN-11 01:00:05 /dba/data/data_ts01.dbf
6 Full 33971595 08-JUN-11 01:00:05 /dba/data/index_ts01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
1123 Full 593.09M DISK 00:04:10 09-JUN-11 01:04:15
BP Key: 1123 Status: AVAILABLE Compressed: YES Tag: TAG20110609T010005
Piece Name: /oracle/rman/dbbak/Daily_bak_1459801106_3amedl4l_1_1.bak
List of Datafiles in backup set 1123
File LV Type Ckp SCN Ckp Time Name
1 Full 36502391 09-JUN-11 01:00:05 /dba/data/system01.dbf
2 Full 36502391 09-JUN-11 01:00:05 /dba/data/undotbs01.dbf
3 Full 36502391 09-JUN-11 01:00:05 /dba/data/sysaux01.dbf
4 Full 36502391 09-JUN-11 01:00:05 /dba/data/users01.dbf
5 Full 36502391 09-JUN-11 01:00:05 /dba/data/data_ts01.dbf
6 Full 36502391 09-JUN-11 01:00:05 /dba/data/index_ts01.dbf
RMAN>
Thank you -
Localized text for hour, minute, second, week, today, etc.
You are able to get localized text for the weekday name, e.g. to get your localized name of "monday", use
SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
String name = sdf.format(gregorianCalendar.getTime())for month names, you would use the format String MMMM:
SimpleDateFormat sdf = new SimpleDateFormat("MMMM");Are there additional localized text available through some API? I'm looking for translations for "next", "previous", "day", "week", "month", "year", "hour", "minute", "second", "now", "today", "OK", "Cancel". (Of course, I could translate these myself and offer a MessageBundle, but if there are already translations down there through the API, why do work twice ;-)You are able to get localized text for the weekday name, e.g. to get your localized name of "monday", use
SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
String name = sdf.format(gregorianCalendar.getTime())for month names, you would use the format String MMMM:
SimpleDateFormat sdf = new SimpleDateFormat("MMMM");Are there additional localized text available through some API? I'm looking for translations for "next", "previous", "day", "week", "month", "year", "hour", "minute", "second", "now", "today", "OK", "Cancel". (Of course, I could translate these myself and offer a MessageBundle, but if there are already translations down there through the API, why do work twice ;-) -
In DB2, I can get the value of year, month, date, hour, minute, second from current timestamp by year(), month(), date(), hour(), minute(), second(). Like below SQL,
SELECT current timestamp, year(current timestamp), month(current timestamp), date(current timestamp), hour(current timestamp), minute(current timestamp), second(current timestamp) FROM DUAL
In Oracle, how can I modify above SQL?
That is, do we have the corresponding function to each one of them in DB2?
Thanks,
JJHi Turloch,
Thanks for your help.
Here, I have another question.
How about the days caculation?
For example, in DB2, I have a SQL as below,
select
account_no
from
lit_transaction
where
( start_date + no_of_days days - exp_days days) <= CURRENT DATE
How can I modify above days caculation for Oracle?
Thanks,
J.
Maybe you are looking for
-
Transfer within a company for zero value assets
Hi experts, I am transferring zero value assets (no acquisition cost, no depreciation, zero NBV) from 1 business area to another business area, therefore use tcode ABUMN (Transfer within company code) with transfer variant 4 (Transfer within a compan
-
How do I keep type kit from showing in my CC apps?
After reinstalling InDesign CC on one of my Macs Typekit started showing up as each file was opened. How do I stop this extra step of canceling typekit and then going to Type Manager! We are a service provider and i requier that my clients submitt
-
How can i connect mac book pro to appel tv3
How can i connect mac book pro to appel tv3
-
Compare current value with previous value
Hello, I would like to compare the current value with the previous value of the current value. How can I solve this problem? Maurits
-
Opening JTextPane hyperlink in a browser window
hi I have a hyperlink in a JTextPane how can i open the webpage in a browser window? thanks