473,382 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Date diffrence

I have a table with 3 colums:

Date (datetime)
End (datetime)
Sys_id (INT)

What I need to do is write a query that will do a calculation and
return the diffrence in hours between date and end. I though that
maybe a DATE_SUB would work but I can't seem to get it to do as I
want. Hope someone can help.
Jul 20 '05 #1
4 1615
rubbersoul wrote:
I have a table with 3 colums:

Date (datetime)
End (datetime)
Sys_id (INT)

What I need to do is write a query that will do a calculation and
return the diffrence in hours between date and end. I though that
maybe a DATE_SUB would work but I can't seem to get it to do as I
want. Hope someone can help.

Subtract the UNIX timestamps and that will give you the difference in
seconds.
Jul 20 '05 #2
2metre wrote:
rubbersoul wrote:
I have a table with 3 colums:

Date (datetime)
End (datetime)
Sys_id (INT)

What I need to do is write a query that will do a calculation and
return the diffrence in hours between date and end. I though that
maybe a DATE_SUB would work but I can't seem to get it to do as I
want. Hope someone can help.


Subtract the UNIX timestamps and that will give you the difference in
seconds.


or for hours rounded to the nearest.. (have tested this!)

select
Sys_id,
round((UNIX_TIMESTAMP(End)-UNIX_TIMESTAMP(Date))/3600)
from
tablename
Jul 20 '05 #3
2metre <2m****@xxxhersham.net> wrote in message news:<cm**********@titan.btinternet.com>...
2metre wrote:
rubbersoul wrote:
I have a table with 3 colums:

Date (datetime)
End (datetime)
Sys_id (INT)

What I need to do is write a query that will do a calculation and
return the diffrence in hours between date and end. I though that
maybe a DATE_SUB would work but I can't seem to get it to do as I
want. Hope someone can help.


Subtract the UNIX timestamps and that will give you the difference in
seconds.


or for hours rounded to the nearest.. (have tested this!)

select
Sys_id,
round((UNIX_TIMESTAMP(End)-UNIX_TIMESTAMP(Date))/3600)
from
tablename

This works but dosen't return what I need.

----+---------------------+-------------+--------------------
16 | 2004-10-11 08:05:00 | Problem | 2004-10-11 09:00:00
16 | 2004-12-12 13:00:00 | Problem | 2004-12-14 15:00:00
I tried running your query and I got this:
+--------+---------------------------------------------------------+
| sys_id | round((unix_timestamp(end) -unix_timestamp(date))/3600) |
+--------+---------------------------------------------------------+
| 16 | 1 |
| 16 | 50 |
+--------+---------------------------------------------------------+

I know this is what I initally asked for but I need the first row to
come out as 0.55 for the minutes. Sorry....I don't know if this is as
easy as just removing the round, but I doubt it!
Jul 20 '05 #4
remove the word

round

...

"rubbersoul" <rg*****@vacv.com> wrote in message
news:f0**************************@posting.google.c om...
: 2metre <2m****@xxxhersham.net> wrote in message
news:<cm**********@titan.btinternet.com>...
: > 2metre wrote:
: > > rubbersoul wrote:
: > >
: > >> I have a table with 3 colums:
: > >>
: > >> Date (datetime)
: > >> End (datetime)
: > >> Sys_id (INT)
: > >>
: > >> What I need to do is write a query that will do a calculation and
: > >> return the diffrence in hours between date and end. I though that
: > >> maybe a DATE_SUB would work but I can't seem to get it to do as I
: > >> want. Hope someone can help.
: > >
: > > Subtract the UNIX timestamps and that will give you the difference in
: > > seconds.
: >
: > or for hours rounded to the nearest.. (have tested this!)
: >
: > select
: > Sys_id,
: > round((UNIX_TIMESTAMP(End)-UNIX_TIMESTAMP(Date))/3600)
: > from
: > tablename
:
:
: This works but dosen't return what I need.
:
: ----+---------------------+-------------+--------------------
: 16 | 2004-10-11 08:05:00 | Problem | 2004-10-11 09:00:00
: 16 | 2004-12-12 13:00:00 | Problem | 2004-12-14 15:00:00
:
:
: I tried running your query and I got this:
:
:
: +--------+---------------------------------------------------------+
: | sys_id | round((unix_timestamp(end) -unix_timestamp(date))/3600) |
: +--------+---------------------------------------------------------+
: | 16 | 1 |
: | 16 | 50 |
: +--------+---------------------------------------------------------+
:
: I know this is what I initally asked for but I need the first row to
: come out as 0.55 for the minutes. Sorry....I don't know if this is as
: easy as just removing the round, but I doubt it!
Jul 20 '05 #5

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

Similar topics

7
by: ranjeet.gupta | last post by:
Dear All, What is the diffrence between the below two notation; char bytes; char bytes; both are one bytes, It may be odd to ask question like above, But does it matter if i allocate like...
3
by: | last post by:
is there any performance diffrence between MC++ 2003 ,other .NET languages and MC++ 2005 (cause of an optimization) ???
2
by: dkrysmann | last post by:
Hi, I'm very new to this group and the php, now I've question about date function. I need function how to calculate time diffrence between two dates. First date: $rs['lastBuildDate' is like...
5
by: dost | last post by:
can u tell me the diffrence between...... private public and protected .........in........these.......which one...is access modifier....and which one..is specifier....... and....the diffrence...
8
by: Vijay | last post by:
Can you tell me what is the diffrence between structure and union.
1
by: madhu | last post by:
I want db2 date functions and what is the diffrence between the oracle date functions and db2 date functions?
1
by: jitender164 | last post by:
hello all pls help me to explore the diffrence b/w c and c++ by using a program example code that can illustrate the diffrence between the structure programing and object oriented programing....
3
by: raju123 | last post by:
what is diffrence between c# and vb.net
4
by: lostandfound | last post by:
Hi, I need to transpose the diffrence between two date columns as the total number of rows in the result set. For example: Temp: t1 sno date1 date2 1 12/03/2007 ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.