472,799 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,799 software developers and data experts.

Hour difference?

I need to compute the difference of Time fields, in the format HHMM. Is
it possible to do the math in the Select?
Regards,

BTJ

--
-----------------------------------------------------------------------------------------------
Bjørn T Johansen (BSc,MNIF)
Executive Manager
bt*@havleik.no Havleik Consulting
Phone : +47 67 54 15 17 Conradisvei 4
Fax : +47 67 54 13 91 N-1338 Sandvika
Cellular : +47 926 93 298 http://www.havleik.no
-----------------------------------------------------------------------------------------------
"The stickers on the side of the box said "Supported Platforms: Windows
98, Windows NT 4.0,
Windows 2000 or better", so clearly Linux was a supported platform."
-----------------------------------------------------------------------------------------------
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 11 '05 #1
6 2270
On Mon, Aug 18, 2003 at 16:09:43 +0200,
Bjørn T Johansen <bt*@havleik.no> wrote:
I need to compute the difference of Time fields, in the format HHMM. Is
it possible to do the math in the Select?


Despite what it says in the documentation, you can't use that format
for the type time.
If timestamps will work for you, you can use to_timestamp to convert
to a timestamps and then subtract them to get an interval.
Another option would be to massage the strings to use a : separator
between the hours and minutes fields and then cast the strings to times.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 11 '05 #2
On Mon, Aug 18, 2003 at 17:56:00 +0200,
Bjørn T Johansen <bt*@havleik.no> wrote:
I am already using Time for time fields (i.e. timestamp fields without
the date part) in my database, are you saying this doesn't work???


No. You can't use HHMM format for input without doing some more work.
You can use HH:MM as an input format.

If you already have the data loaded into time fields, you can just
subtract them to get an interval.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 11 '05 #3
I am already using Time for time fields (i.e. timestamp fields without
the date part) in my database, are you saying this doesn't work???
BTJ

On Mon, 2003-08-18 at 17:55, Bruno Wolff III wrote:
On Mon, Aug 18, 2003 at 16:09:43 +0200,
Bjørn T Johansen <bt*@havleik.no> wrote:
I need to compute the difference of Time fields, in the format HHMM. Is
it possible to do the math in the Select?


Despite what it says in the documentation, you can't use that format
for the type time.
If timestamps will work for you, you can use to_timestamp to convert
to a timestamps and then subtract them to get an interval.
Another option would be to massage the strings to use a : separator
between the hours and minutes fields and then cast the strings to times.

--
-----------------------------------------------------------------------------------------------
Bjørn T Johansen (BSc,MNIF)
Executive Manager
bt*@havleik.no Havleik Consulting
Phone : +47 67 54 15 17 Conradisvei 4
Fax : +47 67 54 13 91 N-1338 Sandvika
Cellular : +47 926 93 298 http://www.havleik.no
-----------------------------------------------------------------------------------------------
"The stickers on the side of the box said "Supported Platforms: Windows
98, Windows NT 4.0,
Windows 2000 or better", so clearly Linux was a supported platform."
-----------------------------------------------------------------------------------------------
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 11 '05 #4
On Mon, Aug 18, 2003 at 11:19:35 -0700,
Jonathan Bartlett <jo*****@eskimo.com> wrote:
Is there a way to get an interval in a standard format? It seems like it
keeps changing it's ouput style based on the time length.


Extracting epoch from an interval will return the length in seconds.
(With months treated as having 30 days and years as having 12 months.
But that shouldn't matter for your application.) You can then make
calculations with that number to produce whatever output format you want.

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 11 '05 #5
Is there a way to get an interval in a standard format? It seems like it
keeps changing it's ouput style based on the time length.

Jon

On Mon, 18 Aug 2003, Bruno Wolff III wrote:
On Mon, Aug 18, 2003 at 16:09:43 +0200,
Bjørn T Johansen <bt*@havleik.no> wrote:
I need to compute the difference of Time fields, in the format HHMM. Is
it possible to do the math in the Select?


Despite what it says in the documentation, you can't use that format
for the type time.
If timestamps will work for you, you can use to_timestamp to convert
to a timestamps and then subtract them to get an interval.
Another option would be to massage the strings to use a : separator
between the hours and minutes fields and then cast the strings to times.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #6
Well, that might help, thanks... :)

BTJ

On Mon, 2003-08-18 at 20:47, Steve Worsley wrote:
fingerless=# select '7:43'::time AS start, '12:17'::time AS end,
(('12:17'::time) - ('7:43'::time))::interval AS difference;
start | end | difference
----------+----------+------------
07:43:00 | 12:17:00 | 04:34
(1 row)
Hope that helps.. Just subsitute your column names for the times.

--Steve
Bjørn T Johansen wrote:
I need to compute the difference of Time fields, in the format HHMM. Is
it possible to do the math in the Select?
Regards,

BTJ


---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 11 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Brooks Clayton | last post by:
I have an A97 db on Win2k machine. I have a make table query to update a small db wich we then FTP to our website for customer order status. What is the best way to automate the query to run...
3
by: A | last post by:
Hello, I try to make a Windows Service that doing some action at each begin of hour. I cannot use the task schedule. I have try to use thread, timer ... But nothing is correct. Do you have...
2
by: spoonerstreet | last post by:
I am trying to take standard MS Time: 2/22/2006 8:56:37 AM (stored in MS Decimal Format) and convert it to the half hour of the day it occurred in: 2/22/2006 8:56:37 AM would be in the 18th...
6
by: Dogmar Hoffman | last post by:
Hello, I am trying to use tostring to convert to a 24 hour time format, but am getting the error "No Overload for Method 'ToString'takes '1' arguments". The following is what I have and it...
3
by: Shawn Yates | last post by:
I have a database that I am using as a Time clock where employees can clock in and out. Is there a way to make it so that when they clock out a form would open displaying their work day hour by...
0
by: Rog | last post by:
Who am I?: Hi I am a 'one-man-show' and mainly in the ecommerce and community business based in Western Europe. With over 13 years experience in the internet and telecommunication business, I...
10
ollyb303
by: ollyb303 | last post by:
Hello, Need some help with an Access 2000 query. My query is based on a table which is a log of calls to my company. I am using a date range entered by the user (Date Between And ) and...
5
by: maury | last post by:
Hello, I have an SQL Server table with a (text) field in which there is a data value in this format: 200802290525 I need to build an update query the modifies this value subtracting 1 (one)...
9
by: viki1967 | last post by:
Hi all! This new forum its great! :) Congratulations !!! My answer: why this my code not working? Nothing error but not work the difference.... : <html>
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.