473,396 Members | 2,106 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,396 software developers and data experts.

Subtracting dates gives me what?

When I subtract dates, I can't figure out what I get out. I first I
thought it was in seconds, but that's not it. Then I figured maybe
HHMMSS, but that does not seem to be it too.

How can I subtract two dates and get the resualt in HH:MM:SS format?

Thanks for any help.
-Eddie
mysql> SELECT name, party, NOW(), indate, NOW()-indate, TIME_FORMAT((NOW()-indate), '%H:%i:%s')
from greeter;
+-----------+-------+---------------------+---------------------+--------------+-----------------------------------------+
| name | party | NOW() | indate | NOW()-indate | TIME_FORMAT((NOW()-indate), '%H:%i:%s') |
+-----------+-------+---------------------+---------------------+--------------+-----------------------------------------+
| Jim | 8 | 2005-09-17 22:40:59 | 2005-09-17 19:56:02 | 28457 | NULL |
| Hello | 9 | 2005-09-17 22:40:59 | 2005-09-17 19:56:11 | 28448 | NULL |
| Corrine | 6 | 2005-09-17 22:40:59 | 2005-09-17 19:56:34 | 28425 | NULL |
| Eddie | 6 | 2005-09-17 22:40:59 | 2005-09-17 19:56:49 | 28410 | NULL |
| Ruby | 1 | 2005-09-17 22:40:59 | 2005-09-17 19:57:15 | 28344 | NULL |
| Kevin | 1 | 2005-09-17 22:40:59 | 2005-09-17 19:57:41 | 28318 | NULL |
| Hello | 1 | 2005-09-17 22:40:59 | 2005-09-17 19:59:17 | 28142 | NULL |
| Hi | 1 | 2005-09-17 22:40:59 | 2005-09-17 20:00:16 | 24043 | 02:40:43 |
| Suse | 1 | 2005-09-17 22:40:59 | 2005-09-17 20:01:10 | 23949 | 02:39:49 |
| Gil gil | 6 | 2005-09-17 22:40:59 | 2005-09-17 20:02:05 | 23854 | 02:38:54 |
| Kitty cat | 4 | 2005-09-17 22:40:59 | 2005-09-17 20:02:40 | 23819 | 02:38:19 |
| Tommis | 1 | 2005-09-17 22:40:59 | 2005-09-17 20:05:02 | 23557 | 02:35:57 |
| T | 1 | 2005-09-17 22:40:59 | 2005-09-17 20:06:13 | 23446 | 02:34:46 |
| Hi | 6 | 2005-09-17 22:40:59 | 2005-09-17 20:33:21 | 20738 | 02:07:38 |
| Bob | 4 | 2005-09-17 22:40:59 | 2005-09-17 20:34:22 | 20637 | 02:06:37 |
| Bob | 4 | 2005-09-17 22:40:59 | 2005-09-17 20:40:19 | 20040 | 02:00:40 |
| Johnny | 3 | 2005-09-17 22:40:59 | 2005-09-17 20:46:59 | 19400 | NULL |
| Corrine | 1 | 2005-09-17 22:40:59 | 2005-09-17 20:48:23 | 19236 | NULL |
| Yoda | 1 | 2005-09-17 22:40:59 | 2005-09-17 20:48:38 | 19221 | NULL |
| Eddie | 4 | 2005-09-17 22:40:59 | 2005-09-17 20:55:09 | 18550 | NULL |
| Lucky | 1 | 2005-09-17 22:40:59 | 2005-09-17 20:57:02 | 18357 | NULL |
| Moe | 5 | 2005-09-17 22:40:59 | 2005-09-17 20:58:15 | 18244 | NULL |
| Jonny | 8 | 2005-09-17 22:40:59 | 2005-09-17 20:59:17 | 18142 | NULL |
| Sam | 3 | 2005-09-17 22:40:59 | 2005-09-17 20:59:35 | 18124 | NULL |
| Bob | 4 | 2005-09-17 22:40:59 | 2005-09-17 21:39:30 | 10129 | 01:01:29 |
+-----------+-------+---------------------+---------------------+--------------+-----------------------------------------+
25 rows in set (0.00 sec)

mysql> describe greeter;
+---------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+----------------+
| name | varchar(20) | YES | | NULL | |
| party | decimal(3,0) | YES | | NULL | |
| indate | datetime | YES | | NULL | |
| outdate | datetime | YES | | NULL | |
| id | mediumint(9) | | PRI | NULL | auto_increment |
+---------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
Sep 18 '05 #1
2 6876
Eddie wrote:
When I subtract dates, I can't figure out what I get out. I first I
thought it was in seconds, but that's not it. Then I figured maybe
HHMMSS, but that does not seem to be it too.

How can I subtract two dates and get the resualt in HH:MM:SS format?


Did you notice that there is a whole page about date and time functions
in the manual:
http://dev.mysql.com/doc/mysql/en/da...functions.html
Sep 18 '05 #2
On Sun, 18 Sep 2005 00:01:41 -0700, Aggro wrote:
Eddie wrote:
When I subtract dates, I can't figure out what I get out. I first I
thought it was in seconds, but that's not it. Then I figured maybe
HHMMSS, but that does not seem to be it too.

How can I subtract two dates and get the resualt in HH:MM:SS format?


Did you notice that there is a whole page about date and time functions
in the manual:
http://dev.mysql.com/doc/mysql/en/da...functions.html

Ya, I have been over that page a lot.
I just discover this in the user comments section.

sec_to_time(unix_timestamp(EndDateTime)-unix_timestamp(StartDateTime))

It seems a long about way, but it gets the number I need.

Thanks
Sep 22 '05 #3

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

Similar topics

1
by: Jesse O | last post by:
I have two date fields, start_date and end_date. I'd like to subtract the two dates, and come up with a number (the number of difference between the two dates). What function is there to do...
10
by: Colin Steadman | last post by:
I'm a stupid ASP programmer and I dont do Javascript (except for very simple tasks anyway), and I'm in a bit of a predicament. I've used a javascript table sorting script from here: ...
5
by: SimonC | last post by:
Help needed for a Javascript beginner. As above in the subject... i need a javascript to run this, but not in the form of a web-page. I want to calculate it between 2 fields in a database that...
11
by: Laery | last post by:
Hi, I'm currently adding a new module to an old borland C3.1 application (dos). And I need to calculate a date by subtracting the number of days from a given date. I know I could use an...
6
by: Brian Henry | last post by:
How would i take two dates startdate and enddate and subtract startdate from enddate to figure the number of days between the two? thanks
8
by: Ifollowhim | last post by:
I have a (installation) date in a table that I put in manually. It is the date we want to complete a job. In a form that uses data from that table I want to add a text box that is bound to the...
4
by: David S. Alexander | last post by:
How can I do simple subtraction in an XSLT. I want to read a few attribute values from an XML document, calculate their difference, and transform that value to an attribute in the XML output...
31
by: Spiro Trikaliotis | last post by:
Hello, I have a question regarding subtracting a pointer from another one. Assume I have two pointers p1 and p2, which both point to a memory area obtained with malloc(). Assume p1 = p2 + some...
1
by: kigoobe | last post by:
Well guys, I am storing data in the mysql which when extracted gives this - Array ( => Array ( => 26 => 2007-11-01 => 16:01:00 ...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.