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, 02:10 PM
penkomitev penkomitev is offline
Learning Programmer
 
Join Date: Dec 2007
Location: Plovdiv, Bulgaria
Age: 16
Posts: 30
Rep Power: 4
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, 09:59 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,224
Last Blog:
Ext JS or Ext GWT
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
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
The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-26-2007, 03:36 AM
penkomitev penkomitev is offline
Learning Programmer
 
Join Date: Dec 2007
Location: Plovdiv, Bulgaria
Age: 16
Posts: 30
Rep Power: 4
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 03: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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Peculiar UI Problem Needs Tackling adriyel C# Programming 2 04-06-2008 08:46 AM
i have a problem please help me!!!???? stack Java Help 8 09-22-2007 04:17 PM
[C] Comparison problem Alhazred C and C++ 1 08-29-2007 05:58 AM
Connectionstring Problem mohamedsaleh70@hotmail.co Visual Basic Programming 3 04-15-2007 12:57 PM
A small problem in the output The_Master C and C++ 3 12-13-2006 01:04 PM


All times are GMT -5. The time now is 12:49 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads