List:General Discussion« Previous MessageNext Message »
From:SGreen Date:July 27 2005 5:09pm
Subject:Re: Hour counts
View as plain text  
Gyurasits Zoltán <gyz@stripped> wrote on 07/27/2005 12:57:42 PM:

> 
>  TIMESTAMP() is available as of MySQL 4.1.1.
> 
> I can't use this version because replication working :(
> 
> I use version 4.0.22
> 
> ----- Original Message ----- 
> From: "Martijn Tonies" <m.tonies@stripped>
> To: "Gyurasits Zoltán" <gyz@stripped>; <mysql@stripped>
> Sent: Wednesday, July 27, 2005 6:31 PM
> Subject: Re: Hour counts
> 
> 
> > Hi,
> >
> > Check out the  TIMEDIFF  function.
> >
> > With regards,
> >
> > Martijn Tonies
> > Database Workbench - tool for InterBase, Firebird, MySQL, Oracle & MS 
SQL
> > Server
> > Upscene Productions
> > http://www.upscene.com
> > Database development questions? Check the forum!
> > http://www.databasedevelopmentforum.com
> >
> > I would like to calculate the hour counts from 2 'datetime'.
> > Example:   2005-07-27 18:00 and 2005-07-27 19:30  => 1,5 hour
> >
> > I try this....  but not good!
> >
> > R1 : munkaido_end-munkaido_start  /simple substract/
> > R2 : ROUND(ROUND((end-start)/10000)+
> > (((end-start)/1000-(ROUND((end-start)/10000)*10))/6),1)  /good if is 
in 
> > one
> > day/
> > R3 : ROUND((end-start)/10000)-76  /-76 because from 14. to 15. I don't
> > understand/
> >
> >
> > start               end                  R1                R2 R3
> > 07-14 15:00     07-14 17:30     23000           2.5         -74
> > 07-14 23:00     07-15 01:30     783000         78.5         2
> > 07-14 15:00     07-15 02:30     873000         87.5         11
> > 07-14 15:00     07-14 16:00     10000           1             -75
> >
> > Please help me...    (exist a function for this situation?)
> >
> >
> > Tnx!
> >
> >
> > -- 
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe:    http://lists.mysql.com/mysql?unsub=1
> > 
> 

Then your next option is to convert your datetime values to "seconds since 
epoch" by using UNIX_TIMESTAMP() (see the same link everyone else has 
already given you for details).

mysql>SELECT (unix_timestamp('2005-07-27 19:30:00') - 
unix_timestamp('2005-07-27 18:00:00'))/3600;
+--------------------------------------------------------------------------------------+
| (unix_timestamp('2005-07-27 19:30:00') - unix_timestamp('2005-07-27 
18:00:00'))/3600 |
+--------------------------------------------------------------------------------------+
|        1.50 |
+--------------------------------------------------------------------------------------+
1 row in set (0.00 sec)


Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine



Thread
Hour countsGyurasits Zoltán27 Jul
  • Re: Hour countsMartijn Tonies27 Jul
  • Re: Hour countsJason Pyeron27 Jul
  • Re: Hour countsmfatene27 Jul
    • Re: Hour countsmfatene27 Jul
  • Re: Hour countsGyurasits Zoltán27 Jul
    • Re: Hour countsSGreen27 Jul
      • Re: Hour countsGyurasits Zoltán27 Jul
      • Re: Hour countsEric Bergen27 Jul
        • Re: Hour counts2wsxdr528 Jul
RE: Hour countsTerry Spencer27 Jul