Lost Password?

Go Back   CodeCall Programming Forum > Web Development Forum > Database & Database Programming

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).

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-25-2007, 01:10 PM
penkomitev penkomitev is offline
Newbie
 
Join Date: Dec 2007
Location: Plovdiv, Bulgaria
Age: 16
Posts: 27
Rep Power: 3
penkomitev is on a distinguished road
Send a message via ICQ to penkomitev Send a message via Skype™ to penkomitev
Default A problem with NOW() - date_registered

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 12-25-2007, 08:59 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Age: 26
Posts: 5,864
Last Blog:
Performance or Maintai...
Rep Power: 20
Jordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud of
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

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
MySQL AB :: MySQL 5.0 Reference Manual :: 10.6 Date and Time Functions
__________________
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-26-2007, 02:36 AM
penkomitev penkomitev is offline
Newbie
 
Join Date: Dec 2007
Location: Plovdiv, Bulgaria
Age: 16
Posts: 27
Rep Power: 3
penkomitev is on a distinguished road
Send a message via ICQ to penkomitev Send a message via Skype™ to penkomitev
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT -5. The time now is 11:50 PM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
gaylo565 ........ 18.00000
WingedPanther ........ 15.00000
|pH| ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 66%

Ads