|
||||||
| Database & Database Programming MySQL, Oracle, SQL, PL/SQL, ABAP, Smart Forms, and other databases and languages. A database is an organized body of related information used in many websites (including CC). |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Hello,
Merry Christmas first. A lot of health, hapiness and luck during the new year. Now to the question. I have written one script getting time from MySQL as seconds and the the value is being converted as years, months, days, hours, minutes, seconds. In my opinion, the script is working fine, but the MySQL engine itselfs is making troubles. I attached screenshots to view what exactly the problem is. This is for the field. ![]() A few results from the table ![]() The query, calculating NOW() - date_registered. I added few additional information for you to have better orientation. [SQL]SELECT username, NOW(), date_registered, NOW() - date_registered AS diff FROM users[/SQL] ![]() In my calculations these are 4 hours 16 minutes and 25 seconds. This is 4*3600+16*60+25 = 15385 != 41625 -> for the first row on the second screenshot. I do not want to reinstall engine but first to hear your opinion. Best regards, Penko Mitev |
| Sponsored Links |
|
|
|
|||||
|
I don't see any reason why that shouldn't work but you should use DATEDIFF() to subtract two dates:
Code:
SELECT username, NOW(), date_registered, DATEDIFF(NOW(), date_registered) AS diff FROM users
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog Don't hesitate to ask any questions that you have! Check out our ASCII Calculator! |
|
|||
|
Thank you for your reply. I tried several things including this one. In fact, TIMESTAMPDIFF is the best I found. It returns the result into seconds and I have a class called 'duration', which converts it into years to seconds(array elements) and I can use them easily. The problem with the method above was explained to me by one guy in one bulgarian forum. Here is a translation of his answer:
In the documentation of the function NOW is written that it returns the result in format YYYYMMDDHHMMSS.uuuuuu, so you are substracting dates: 20071225191625.000000 - 20071225150000.000000 = 41625 20071225191625.000000 - 20071224110227.000000 = 1081398 ... so there is nothing surprisely in the returned result. In fact, I understood it works only if the differences is 59 minutes maximum. When Hours are included it makes this problems. Last edited by penkomitev; 12-26-2007 at 02:39 AM. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Peculiar UI Problem Needs Tackling | adriyel | C# Programming | 2 | 04-06-2008 07:46 AM |
| i have a problem please help me!!!???? | stack | Java Help | 8 | 09-22-2007 03:17 PM |
| [C] Comparison problem | Alhazred | C and C++ | 1 | 08-29-2007 04:58 AM |
| Connectionstring Problem | mohamedsaleh70@hotmail.co | Visual Basic Programming | 3 | 04-15-2007 11:57 AM |
| A small problem in the output | The_Master | C and C++ | 3 | 12-13-2006 12:04 PM |
| John | ........ | 223.00000 |
| dargueta | ........ | 168.00000 |
| Xav | ........ | 164.00000 |
| gaylo565 | ........ | 18.00000 |
| WingedPanther | ........ | 15.00000 |
| |pH| | ........ | 15.00000 |
| Johnnyboy | ........ | 3.00000 |
| navghost | ........ | 1.00000 |
Goal: 100,000 Posts
Complete: 66%