Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    MYSQL




Selecting Date Time Field, Difference In Minutes


I wonder if is there any way to select from a table all the records
which has a Date Field that is at least five minutes old?

In other words, I have a table with a date field and I need to select
all the records that are older than five minutes, has their date field
updated before five minutes.

Usually I do it with days by using the to_days() function and comparing
the date to now: (to_dayss(now()) - to_days(somedate)).




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Calculating Time Difference In Minutes Between 2 Times
I have two columns in a table start_time and end_time (stored as datetime). I wish to work out the time difference in minutes between these two values. If the difference is 1hr 30 minutes I wish to get 90 (mins)

I have tried:

SELECT TIME_FORMAT(TIMEDIFF(start_time, end_time), '%i') FROM table ...  This returns justs the minutes (e.g. 30)

and

SELECT TIME_FORMAT(start_time - end_time, '%i') FROM table .... no such luck.

How To Substract Minutes From A Time Field In Mysql Query?
I have a problem, i want to substract minutes from a time field in a mysql query, i'm trying with the next query:

UPDATE TblOrders SET TmHours = TmHours - '00:09:00';

In the query I want to substract 9 minutes from all time fields named TmHours in the table, the datatype for the field TmHours is time.

Need SQL To Calculate Difference Between Two Date/time
I need difference between two date not only in terms of day or hour or minute or second as outputted by following stmt.

SQL
SELECT
TO_DAYS(NOW()) - TO_DAYS(��-09-16 11:45:00') AS diff_in_whole_days,
ROUND((UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(��-09-16 11:45:00')) / 86400, 1) AS diff_in_days, 
ROUND((UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(��-09-16 11:45:00')) / 60 / 60, 1) AS diff_in_hours,
ROUND((UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(��-09-16 11:45:00')) / 60, 1) AS diff_in_minutes,
UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(��-09-16 11:45:00') AS diff_in_seconds;

But I need the difference by days and the remaining hours, and remaining minutes and so on as shown below example:

Difference bet 2007-09-17 15:45:14 and 2007-09-16 11:15:00
is 1day 4hr 30 min 14 sec.

I need these all in sql statements for this requirement.

Date Field, Time Field, Sort By Date And Time
I have a MySQL date field (e.g 13/12/2006) and a MySQL time field (e.g.13:00) in the same row.

I'd like to join these two fields to make a date/time field (e.g. 13:00 13/12/2006) on the fly and to be able to sort the query results on the resulting field.



Retieve Only The Difference In Minutes Between Two Dates
i am just lookin for a func or way about to retrieve the
difference in minutes between 2 dates which are of DATETIME data type
for induvidual records help in this regard is highly solicited.

Selecting The Highest Valued Date/time For A Particular Day
I'm new to MySQL and I am having a problem selecting the highest
valued date/time for a particular day. Here is the table structure:

Function To Extract Difference In Minutes From DateTime Variables
I need to compare a datetime field in my database with the current time
and return only the records that are 5 minutes old or older. Is there
any way to do it? Any function to it?

I use to_days() when I am doing the same thing but with days instead of
minutes.

Select Date Only From Date Time Field
if I have "Date Time" field , How can I get the Date only from this field.

Date/time Field Update Only Date
I have a field(tmMessage) in a table, it's a date/time struct.
it looks like "2003-09-21 15:52:35"

All I want to do is change the date in this field.
I want the time to stay the same.

Date/time Field Update Only Date
I have a field(tmMessage) in a table, it's a date/time struct.
it looks like "2003-09-21 15:52:35"

All I want to do is change the date in this field.
I want the time to stay the same.

Minutes + TIME = TIME Function
I need some way to convert minutes (e.g. 80 mins) to SQL TIME (e.g. 01:20:00) in order to add it to another TIME var.

Is there any way to do this? I really dont want to convert my whole db. Basically, I want to do: e.g. 80 + 10:00:00 = 11:20:00.

Date/time Field Type
I want a field to automatically record the date/time each time a record is written to the db. Do I want that field to be of type DATE, DATETIME, TIMESTAMP…? My book is less than clear.

Date Field, Time Field
I have a MySQL date field (e.g 13/12/2006) and a MySQL time field (e.g.13:00) in the same row.

I'd like to join these two fields to make a date/time field (e.g. 13:00 13/12/2006) and to be able to sort the query results on the resulting field.

Selecting Records From Database Entered Less Then 30 Minutes Ago?
I have tryed everything to select records from the database that have been entered less then 30 minutes ago. I have the time/date stored as a TIMESTAMP, so i need to find a way of returning the records.

Combining Date And Time Fields Into A Datetime Field
I have a table with separate Date and Time fields.

Is there a way to either:

1. Convert the date and time fields into a combined datetime field?

or

2. Create a datetime value in the select statement so I can select all records before a given date and time?

Field To Populate With Current System Date And Time
How can I populate a field with current system date and time? Is there an option to automatically populate this when a record is inserted?

Time Difference ..?
How can I find the time difference of following two times.....

1) 9/6/2006 11:00:03 PM
2) 9/7/2006 1:00:25 AM

Time Difference
<%
onlndt = now() - 0.004

onlinemembers = conn.execute("SELECT count(*) FROM members where lastlogindate > '"& onlndt &"' ORDER BY lastlogindate ")(0)

%>

I am trying to count the number of members logined last one minute or another time range. But onlinemembers always shows "0"

Time Difference
How can i do a calculation on two times - ie work out the differences between a start and end time, i see that mysql has longtime or something similar to do this - is thereany tutorials

Average Time Difference
I have a table which includes two timestamps - creationTS and processedTS.

I want to run a query that tells me the average difference between these two timestamps on a minute by minute basis, i.e. one row for each minute of the day, containing the total messages created in that minute and average amount of time it took to process data created in that minute.

Is this possible in a query, or do I need to grab each entry and use PHP to work out the average processing time?

Difference Between Two Time Enteries
I have two field in a db, one called begin_time and one called end_time they are both stored as datetime types.

currently two entries are:

begin_time             end_time
2007-04-12 12:18:00    2007-04-12 14:39:00

I need to work out the difference in hh:mm:ss between the begin and end times.

I have tried

select date_format(end_time, '%H:%i:%s') - date_format(begin_time, '%H:%i:%s') from tablename where id =1;


it just returns 2 in no format.

How do I get it to return the actual difference in hh:mm:ss?

Calculate Time Difference
I have a column called timeinterval which is of type datetime. I need to select the first and the second timeinterval and find the difference between them. if it is greater than 30 seconds i need to do something. how to achieve this. I tried using datediff and timediff.

eg:
select TIMEDIFF ('2006-10-31 11:50:31' , '2006-10-31 11:50:01')
eg:
select DATEDIFF ('2006-10-31 11:50:31' , '2006-10-31 11:50:01')

but it is saying you have an error in sql syntax. Iam using mysql 4.1.0 version.

one more thing. If the query works fine how can i check whether it is greater than 30 seconds. If suppose it is greater than one day it is going to return 1. How to check this condition also.

Calculating Time Difference
I have a task where I need to calculate the hours between two dates. However, they only want to calcute the time during Mon-Friday from 8-5. So if someone enters a question at 4:59PM on Friday and someone responds to them on Monday at 8:30. The user wants to see 31 minutes as the response time. I see that I have a function called dayname to get the Monday-Friday. However, I have no idea how I might actually use this to calculate the time lapsed. I need it to somehow ignore Saturday/Sunday.

How To Determine Difference Between Two Time Stamps
I have two fields in a table

timestart
timestop

and they have values such as

2006-05-11 12:07:18
2006-05-11 12:22:56

How to make a query that'll extract out the days/hours/minutes/seconds differences between the two dates?

Time Difference Between Records From Two Tables
I have two tables with data from two separate data loggers. The timestamps of the records are not perfectly synchronised (eg. 2005-07-11 22:50:00 and 2005-07-11 22:49:58). All data must be joined to one table and all records that are out of sync by more then 30 seconds must be rejected. I tried somethig like this: Code:

Time Difference Between TIMESTAMP Fields
Anyone know how to return the difference in time (in seconds) between two TIMESTAMP fields?

I am using MySQL ver 4.0.12 thus TIMEDIFF and all those other fancy functions dont work!

PHP/MySQL Sorting By Date & Time (using Non Military Time)
This is probably a simple issue but I have searched online and can't find an answer.

I am using PHP/MySQL and I guess the most intuitive would be to have three select boxes containing HOUR / MINUTE / AM,PM option. Then store the time into mysql using there functions so I can output the data sorting them all by date and time. All the examples I have seen are for military time only but I'm sure there has got to be a simple mysql function or php function that converts non military to military and a formatting function to display with the AM / PM. But I have not found it.


Date Difference
how can I modify this query so I get only the past week's ventas? there is a field called "fecha" that stores the date of the selling.

SELECT ventas. * , ventas.importe_acordado - SUM( pagos.importe ) AS valor_dinamico
FROM ventas
LEFT OUTER JOIN pagos ON pagos.venta = ventas.id
GROUP BY ventas.id
HAVING valor_dinamico >0

Date Difference
I am using version 4.0.18 and need to work out the difference between 2 dates, say 2005-03-21 and 2005-03-25.

Unfortunately DATEDIFF is not available till 4.1.1 and i'm not in a position to upgrade as yet.

How can I do this alternatively within a MySQL query?

Date Difference
I would like to get the the diffrence between two date say DATE1 and DATE2 and need the result in yyyy-mm-dd format. ie I need the result in years, moths and and days. can anyone tell me the solution for it ?.

Date Difference
ow to make a date difference like this: CURDATE()-start ... where start is a field which stores a date..where user sign in..
I want this difference to be display in this way: 2 Days 4 hours 30 minutes 19 seconds ... ONLY WITH MYSQL

Difference Between Date
What is the best way to find the difference between two dates in a database??
I have a 'received' and a 'replied' field and i want to find the response time

Date Difference Sum & Array
I'm trying to work out the interest on a whole bunch of records and then add them all up - hopefully in one query.

This would be a standard query if I wanted to get a list of all charges and the interest rate

$cID = $_GET['cID'];

SELECT date_charge, amount, interest_rate
FROM charges
LEFT JOIN claims ON cID = '$cID'
WHERE chcID='$cID'

$interest_rate_f = $interest_rate / 36500;
But how would I go about getting that one query to perform the following calculation?

amount * ( curdate('Y-m-d') - date_charge ) * interest_rate_f

amount = 27.50
curdate = 2006-10-13
date_charge = 2000-08-25
interest_rate_f = 0.000219178

$interest = 27.50 * ( 2240 ) * 0.000219178 = 13.50

And then add all the $interest up in the query to output it as
$interest_rate_sum
PHP Version 4.2.3




Calculating Date Difference With PHP
I know nothing about MySQL (I'm more of a low level php guy). I'm building a reminder script that will remind the site admin to send out a newsletter. I want to send my reminder email email only if 30 days have passed since the last newsletter sending.

I've already setup a database that will be updated with the current date when a newsletter is sent out.

I found this function, which seams useful.

PHP

mysql> SELECT DATEDIFF(&#55614;&#57149;-12-31 23:59:59',&#55614;&#57149;-12-30');
        -> 1

My guess is I could do something vaguelylike this:

PHP

$x = SELECT DATEDIFF(' CURRENT_DATE()',' the date in the dabase');
        -> the difference between the 2 of them

From there I could use php to say if $x is greater than 29 days, send the email.

I was wondering if anyone could help me with the syntax / methodology of achieving this.

If MySQL is not the right method, please let me know. I was told that MySQL is the "best" way of doing this.

Computing Date Difference
I need to run a query which pulls out all records that have been created within the last week. I'm storing the creation date in a date field, but for the life of me can't think of how to pull out what i need.

Difference Between Two Field
What is the SQL code to retrieve the difference between two field values? Field A minus Field B.

ID Difference Field
I am running a query off of one table of articles that simply returns articleID, title, article, and image

Code:


SELECT articleID, title, article, image
FROM Articles

The articleID is an auto-increment INT field and I just need to have the query also return one more field that will indicate the difference between that particular articleID and the max articleID. So, for example, if an article has articleID 100 but the most recent articleID is 120 I need a field to return the number 20.
I know how to do this with a subquery but I am using MySQL version 4.0.1 so can’t use subqueries.

Date Difference In MySQL Query (3.23.50)
I am trying to calculate the age of my customers. The birthdates are stored: 19621222

I am trying:

Select (Current_Date - BirthDate)/365 as Age from Customers

Of course that is not the solution. Is there a function i can use?

Date-time Overlaps Another Time
had a time question in mysql...
i have a start and end time for a meeting table and i am comparing whether a new meeting conflicts with another meeting in same room on the same date.
i was wondering if i could check whether the 'date-time duration' in anyway overlaps another meetings date-time duration. visualized below...
............|____compareToThisMeeting__|
.....|_________meetingNewOverlaps__________|
i was doing something dumb before i realized i needed soemthing more complex (checking whether the start time of new meeting was 'BETWEEN' the start and end times of a meeting and whether the end time time is as well but i forgot the duration/middle value hehe).
(using asp)
and just returning booleans with a mySQL SELECT statement is what i am looking for like...
//within a loop in asp for meetings on same date/room
"SELECT '"+ year+"-"+month +"-"+day +" " + startHourString +":" + startMinuteString +":00''"+ " BETWEEN '"+ thisMeetingStart +"' AND '"+ thisMeetingEnd +"'"; (this doesnt cover the 'middle' overlap areas though)

Selecting Rank Over Time
I have 4 colums in my table.. they are id(int), usrid (int), datestamp (date) and credits(float).

here's what i'd like to do.. select the numeric rank of a given userid over the past 30 days based on the most credits... ideally i'd like it all to be in one query but that may not be possible.. any ideas are welcome here, i'm stumped on this one.. so far all i've been able to do is select all the entries from the last 30 days..

SELECT *
FROM daycredit
WHERE TO_DAYS( NOW( ) ) - TO_DAYS( datestamp ) <= 30
and usrid = $usrid LIMIT 0, 30

Loading Date Format 1-1-2007 To Date Field Doesn't Work
I'm trying to load the date into a date field in mysql so that I can sort by date, but the date field in mysql is yyyy dd mm or yyyy mm dd so it doesn't load. What can I do?

How To Convert A Varchar Field Into Proper Mysql Date Field?
I have a database in which the date is stored in varchar field in a following format: d-m-Y (06-08-2007), now the problem is that I want to change that field into mySQL date field as well as convert my older dates into MySQL date format i-e Y-m-d (2007-08-06)..

There are about 300 old entries..is there a way I can do that automatically without manually re-entering the dates again?

Selecting By Date
I'm trying to do a very simple thing: I have in my DB a row called at_date, in it I enter a 10 digits number of date, like: 1171869716.

How can I select all the data from the table where the month is the current month (and year of course), or any month I choose?
Better saving the dates in a different format?

Selecting By Date
I have a table like this:

CREATE TABLE foo (
MyID INT NOT NULL AUTO_INCREMENT,
MyDate DATE NOT NULL,
PRIMARY KEY(MyID)
)

How can I select entries/rows of the above table which have MyDate closest to the current date? I.e. 2 rows which have MyDate set to '2004-7-15' and '2004-3-20'. The 1st row must be selected 'cos it's closer to the current date (2004-9-8).

Selecting By Date
I am setting up a transaction reporting system and am developing a page which lists the past user transactions.

What i want to be able to do is set it so that I can view all the transactions from yesterday, the last week, the last month and the last year...

is there an easy way of doing this

I have set it so i can view all transactions from the day by using

(Select * from transactions where trans_date = NOW())

is there a way to do the oyher 4 examples like this method??

Selecting By Date...Whats Better?
For example you want to select blog posts from a table by year (2007) or combination year and month (2007-02). Whats better where-clausing the date column with ....

Selecting A List Of Date
Is there any way to select a list of date by specifying the from date and the to date.
Such as:

From Date : 01-01-2005
To Date : 05-01-2005

Results
-----------
01-01-2005
02-01-2005
03-01-2005
04-01-2005
05-01-2005 .

Selecting Date Records
What is the most efficient way to select records based on a field called NOW
which contains a date or a datetimestamp

I use:
SELECT * FROM `TBL` WHERE
DATE_ADD( `TBL`.`NOW` , INTERVAL 3 MONTH ) > CURDATE( );

Is this the best way?

TIA
[color=blue]
> Nicolaas[/color]

Selecting Date Ranges
I have many files dating back 15 years. I want to be able to display the records by the following different cases:

- Select all from current week
- Select all from current month
- Select all from past 12 weeks
- Select all from past 12 months
- Select all from specified week
- Select all form specified month
- Select all from records (i got this one down)

All the records are in the database and the dates are in DATETIME format yyyy-mm-dd.


Copyright © 2005-08 www.BigResource.com, All rights reserved