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




Truncated Time Values Using TIMEDIFF With ORDER BY Query


I'm using the following query:

SELECT glider, timestamp, TIMEDIFF(timestamp, UTC_TIMESTAMP()) AS last_contact
FROM surfacings
INNER JOIN
(SELECT MAX(timestamp) AS most_recent FROM surfacings GROUP BY glider)
AS tmp
WHERE surfacings.timestamp = tmp.most_recent;

to calculate the amount of time that has elapsed since the last inserted timestamp for each glider. Everything works fine: ....




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Form Values Are Truncated
I'm building a member signup form. Fields that contain more than one word
are being truncated when being inserted into the MySQL table.

I'm using this code that I got from one of my PHP books.

$as_addr1 = addslashes($_POST['addr1']);$tr_addr1 = trim($as_addr1);

So, if I post "1122 Boogie St." it gets inserted as "1122". If I remove the
"addslashes" portion, only using trim, I get the same result.

Here's the query:
$query = "INSERT INTO subscribers
(email,password,fName,lName,addr1)
VALUES
('$tr_email','$tr_pass','$tr_fName','$tr_lName','$ tr_addr1'";

echo $query;

Here's the echo:
INSERT INTO subscribers (email,password,fName,lName,addr1)
VALUES('j@j.com','11111111','Jim','Johnson','78797 State')

I have other fields in the table that are doing the same thing. All fields
are varchars of varying length. Field "addr1" is varchar(50).

Form Values Are Truncated
I'm building a member signup form. Fields that contain more than one word
are being truncated when being inserted into the MySQL table.

I'm using this code that I got from one of my PHP books.

$as_addr1 = addslashes($_POST['addr1']);$tr_addr1 = trim($as_addr1);

So, if I post "1122 Boogie St." it gets inserted as "1122". If I remove the
"addslashes" portion, only using trim, I get the same result.

Here's the query:
$query = "INSERT INTO subscribers
(email,password,fName,lName,addr1)
VALUES
('$tr_email','$tr_pass','$tr_fName','$tr_lName','$ tr_addr1'";

echo $query;

Here's the echo:
INSERT INTO subscribers (email,password,fName,lName,addr1)
VALUES('j@j.com','11111111','Jim','Johnson','78797 State')

I have other fields in the table that are doing the same thing. All fields
are varchars of varying length. Field "addr1" is varchar(50).

Suggestions?

Form Values Are Truncated
I'm building a member signup form. Fields that contain more than one word
are being truncated when being inserted into the MySQL table.

I'm using this code that I got from one of my PHP books.

$as_addr1 = addslashes($_POST['addr1']);$tr_addr1 = trim($as_addr1);

So, if I post "1122 Boogie St." it gets inserted as "1122". If I remove the
"addslashes" portion, only using trim, I get the same result.

Here's the query:
$query = "INSERT INTO subscribers
(email,password,fName,lName,addr1)
VALUES
('$tr_email','$tr_pass','$tr_fName','$tr_lName','$ tr_addr1'";

echo $query;

Here's the echo:
INSERT INTO subscribers (email,password,fName,lName,addr1)
VALUES('j@j.com','11111111','Jim','Johnson','78797 State')

I have other fields in the table that are doing the same thing. All fields
are varchars of varying length. Field "addr1" is varchar(50).

Sorting Time Values
I have been trying and trying to properly sort records through a mySQL
query. I have hour, minute and AM/PM values stored separately in a
database as varchars. I'm trying to concat those, cast them to a time
value and sort them. I have found that it sorts some properly but other
it does not.

The following query:

CAST(CONCAT(hour, ':', minute, ' ', ampm) AS TIME) AS myTime
ORDER BY myTime

Sorts some results like this:
10:30 PM
8:30 PM
9:30 PM

But other are perfect:
10:00 AM
11:00 AM
12:00 PM
1:00 PM
2:00 PM
3:00 PM
4:00 PM
5:00 PM

These exact results we part of the same recordset. Can anyone help me
with this?

Displaying Time Values
When I link a MySQL table containing a TIME column to Microsoft Access the
value does not display. If I edit the value it updates correctly in mysql
but if I refresh the Access datasheet view the value disappears and the
column shows as blank.

Can anyone tell me how to display time values in Access.
I am using MySQL ODBC driver 3.51, MySQL 4, Access 2002

Elapsed Time Between 2 DateTime Values
MySQL Version 4.0.20 on a Linux server.

How does one get the elapsed time between (2) DateTime values?
I need the answer to the nearest minute.

Is upgrading to Ver 5 with its more robust date/time functions the only
solution?

You can directly subtract 2 DateTime values and a long integer results.
What is that number?

Working Wit Date/time Values
I'm using the following query: Quote: SELECT * FROM IT_event_cal WHERE '$date' BETWEEN start_date AND stop_date

Where start and stop_date are of type date/time (0000-00-00 00:00:00).

For this particular query, I'd like to match a particular date (0000-00-00), and any time. How can I make the time part a wild-card value?

Order By Time
I have three colums related to time in a table.(There are many other fields)
1. intHrs - To store Hour value of time
2. intMins - To store Minute value of time
3. vchAmPm - To store wheather it is AM or PM
I want to select the rows order by time with 24 hour format something like

SELECT * FROM table WHERE condition ORDER BY ........

Order By Time Problem
Im have a Time field that im using to sort the records chronologically. Im storing the 12pm-24hr time as 00hr, since there isnt a real time of 24hr.
So, the problem is that when i Order the info by the time field the 00hr records appear at the start of the list instead that at the end (after the 11:59pm). I want them at the end because im using them as the End of the day, not the start of one.

Im ordering the field with this:

ORDER BY coalesce(time, 24)
What can i do to fix this?
Should i be storing the 12pm as 24hr? (i tried that, but the order by showed another value for the 24hr time)


ORDER BY RAND() Same Every Time
I'm trying to get a random record from a table, but the overwhelmingly recommended method - "SELECT * FROM table ORDER BY RAND() LIMIT 1" - gives me the same record every time.  When I try the query without the LIMIT clause, I can see that the records are indeed in an order that cannot be explained as anything but random (i.e. not the order I entered them, and not the order of the primary key), but when I run the query again they repeatedly show up in the same "random" order.  Is there something I need to do to seed it so that my results change?  I see no mention of this anywhere - everyone seems to act as if this query will simply work.

ORDER BY Date And Time
I am using php to extract variables from a MYSQL database that get loaded into a calendar application. Most everything works great. The only problem occurs when more than one event occurs on the same day. The event date and time are stored as separate variables in the database, thereby making it difficult to ORDER BY date and time. The result is that all of my events appear on the proper day, but they do not appear in chronological order. Is there a way to order by date and time?

I currently have the following:

Code:

$SQL_Query = "SELECT eventID, eventDate, startTime, endTime, title,
description, linkName, hyperlink FROM events ORDER BY eventDate";

Order By Date AND Time
I have two fields in my database...

DATE > YYYY-MM-DD
TIME > HH:MM:SS

I want to order by date AND time, how can i go about this without making a TIMESTAMP table using the UNIX timestamp??

Date/Time As A Default Values For A Table Column
I am new to mySQL, so this question might be simple.I want to add a default value to a column that is the current date/time. I am using the mySQL Administrator and will not allow me to use a function like CURRENT_TIMESTAMP() or NOW() as a default value. I used to do this with other databases (I always add a column to all of my tables called InsertDateTime and UpdateDateTime. It helps to track down data entry problems)

Order By Difference Between Values
Is it possible using mysql to order data by the difference between two values?

For example, I have a table with id, value 1, value 2

At the moment I 'select id from table orderby value 1 desc'

but what I'd really like to do is 'select id from table order by (value1 - value2) desc'

The 'value 1 - value 2' may sometimes be a negative number if that makes any difference (value 2 may be a larger number that value 1)?

Order By Specific Values
Is it possible to order by specific values in a column. For example a
column may contain values like N, N1, N2, S, S1, S2, R, T. I want to
order by in such a way that all the records with N, N1, or N2 in that
specific column will show up on the top. All the records with S1, S2
values will show up next and finally all records with R and T values
in that specific column will show up. Please give me the select
syntax.

ORDER BY And Numeric Values
I'm trying to pull rows out of my table and then order them with a simple ORDER BY, the only problem is, I'm trying to order by numeric values that have been saved as varchar.
This is really screwing up the ordering, for example, 949,746.00 is coming up as being greater than 24,000,000.00. I can't merely change the column type to numerical because the table is being generated dynamically--I don't know which columns are going to contain numbers and which are going to have text.
I'm using PHP to generate the MySQL statements to make the tables, so I figure I could write a check to see which columns have values of numbers, then change its type. This would take considerable time though, so I was hoping that there is an easier and quick solution that I'm probably just overlooking.

ORDER And Decimal/float Values
Which is the most efficient way to order database records by a field/column containing decimal/float values (some with up to 5-6 decimal points) accurately?

Let's say I have a table named "ratings" and in this table, I have a field named "votevalue". I'll execute a query like this :

mysql
SELECT * FROM `ratings` ORDER BY `votevalue` DESC LIMIT 25

The datatype of the "votevalue" field is FLOAT.
I've tried others such as DECIMAL and INT, but they're not accurate either.

Problem is that this is not accurate.
I've worked on some "workarounds" using PHP to sort the records, but it slows down my script which I don't want.

ORDER BY: Null Values At The Bottom
I'm ordering a table by a TIME field in ASC order. The time field can be NULL. So, when i order it, the NULL values appear at the top and i want them at the bottom, after the rest of the timed entries.

Anybody knows how to do this? I tried with the COALESCE() function, but i think it didn't do it right.

Order By Desc On AVG(value) => NULL Values In First
My query is :

SELECT AVG(sucre) AS sucre, AVG(qualite) AS qualite, AVG(gout) AS gout, parfum, marque, count(sucre) AS nb_eval, tabacs.id
FROM tabacs
LEFT OUTER JOIN tabacs_notes ON tabacs.id=tabacs_notes.tabac
GROUP BY tabac, tabacs.id
ORDER BY sucre DESC
LIMIT 00, 10

According to mysql documentation, NULL values of "sucre", "qualite" and "gout" must be in last with this query :

"When using ORDER BY, NULL values are presented first, or last if you specify DESC to sort in descending order. Exception: In MySQL 4.0.2 through 4.0.10, NULL values sort first regardless of sort order. "

However NULL values are in first.

Creating Column Of Unique Values In Order To Have A Primary Key
I have a flat file that has no columns with unique values.In other words, there is no column available that I can define as the PRIMARY KEY, and thus, cannot incorporate the data into a table.

So, my question is this: How do I modify the table so that I can insert a column of unique values for each record? A column of unique values would be something as simple as a letter followed by the row number of the record (e.g, T1, T2983, etc.).

Text Is Truncated
I am using MYSQL 4.4 / PHP. On updating the table from a from the text gets truncated after special characters, like ' or &. Also the text gets truncated after 34,745 chracters.

What can be done to avoid this problem.

Leading Zero Truncated
i have table with column id of int(4) unsigned zerofill
when i store 1 to it get stored as 0001 but when i try to fetch it ,i have 1 instead of 0001 . i want to get it as 0001 without truncating the leading zero .
i dont want to change datatype in databse.
my query is select max(id) from table
i m using php as frontend but when tried in phpMyAdmin it shows 0001 even there.

Timediff
I had a query like this

SELECT * FROM table WHERE timediff(sysdate( ) , columnname ) <25

worked before but suddenly it is not working... I tested locally and also fine.

i hosted in shared hosting...did hoster blocked certain mysql functions?

SUM Of TIMEDIFF
SELECT TIMEDIFF(time_end, time_start)....(time_end and time_start are DATETIME) and their DIFF is ALWAYS time...

The problem is that when I use SUM on TIMEDIFF I get some strange results..I found a workaround but I don't think that this is the right method....(although it works)

SELECT SEC_TO_TIM(SUM(TIME_TO_SEC(TIMEDIFF(time_end, time_start))))...

WHich basicly means that if I want to SUM the TIMEDIFF result(which is TIME) I have to first convert the TIME to SEC and then SUM and then back to TIME with SEC_TO_TIME....

Is this the only way to SUM the TIME?Or is this a "feature" :)

Truncated Incorrect DOUBLE Value
Ignore found the error finally.

Timediff Format DD HH MM SS
timediff(datetime1,datetime2)

How to get the difference in days Hours Minutes Sec (DD HH MM SS) format?

Aplly Timediff()
i've a table like this:
1 17:00
2 18:00
3 19:00

i should make the time difference between each row and then sum everything: (18:00 - 17:00)+(19:00-18:00) = 2hours

how could i solve it

SUBTIME() Vs TIMEDIFF()
I was planning on using it in my query for computing employee lates. For example, an employee's shift is from 7am - 4pm and he comes in at 7:30am. I would like to use either of the time functions to compute the number of minutes late. Same goes for overtime and undertime.

Timediff Overflows
mysql server version Mysql 4.1.18-nt-max

I have weird issue when specifing dates that are far away one from other:

 select timediff('2999-12-31 23:00:00','1500-01-01 00:00:00') as t 

sometimes i get negative time values, sometimes 0 or sometimes simply wrong values... which might indicate overflow...

manual says that timediff() accepts datetime datatype that ranges from '1000-01-01' to '9999-12-31'
so this function should handle correctly any dates within this range...

Is this a known issue? Can i do something about it (like upgrading mysql instalation)?

Column Data Truncated In 4.1 Now Errors In 5.0
I wrote an application in MySQL 4.1 and recently tried to run it on a MySQL 5.0 installation. One of my queries was updating a varchar(5) column with 15 characters of data. In MySQL 4.1 the update truncated the data and didn't error. In MySQL 5.0 it raises an error and the query fails. I looked on the MySQL site for a flag that might explain this behavior difference but couldn't find one. Did something change between 4.1 and 5.0 related to this? Is there a flag that I have set on my 4.1 install that I don't know about? I used a XAMP-Win32 installation to get my MySQL, etc.

Truncated Fields Using Crystal Reports V9
I am using CR 9 and a MySQL database (XP Pro OS). I have updated CR 9 to address MySQL database issues. I have constructed a SQL query and am running it from within the Command feature. The results I am getting indicate that string fields are getting arbitrarily truncated. For example I have a field in the database which is varchar 100. The SQL output sets the field as a String [5]. I am having similar difficulty with other string fields which may truncate at different lengths. Code:

Timediff() And Negative Results
timediff('2006-03-08 22:38:42','2006-03-09 08:47:03') = -13:51:39

How can I make it not output negative numbers when the days increase?

Using Variables As Data In Timediff();
how can i use variables as data inputs to:

mysql>select timediff();

TIMEDIFF Failure After Moving From MySQL 4 To 5
I've already figured out what has happened, but check out this query:

SELECT
TIMEDIFF(&#392007;-01-31 01:01:01',&#392006;-06-12 01:01:01') as timediff,
DATEDIFF(&#392007;-01-31 01:01:01',&#392006;-06-12 01:01:01') as datediff,
UNIX_TIMESTAMP(&#392007;-01-31 01:01:01')-UNIX_TIMESTAMP(&#392006;-06-12 01:01:01') as unixtimediff
Pretty straight forward, however, observe the results in Mysql 4 vs. 5:

MySQL 4:

+------------+----------+--------------+
| timediff | datediff | unixtimediff |
+------------+----------+--------------+
| 5592:00:00 | 233 | 20134800 |
+------------+----------+--------------+

MySQL 5:

+-----------+----------+--------------+
| timediff | datediff | unixtimediff |
+-----------+----------+--------------+
| 838:59:59 | 233 | 20134800 |
+-----------+----------+--------------+
Drove me NUTS till I figured out that MySQL 5 truncates your values! Yay! See the warning after the mysql 5 query reads:

+---------+------+----------------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------------+
| Warning | 1292 | Truncated incorrect time value: &#395592;:00:00' |
+---------+------+----------------------------------------------+
My solution, already shown with the unixtimediff, was pretty easy and looks like it will work just fine.

I couldn't find note of this change anywhere, so I figured I'd post in case anyone ever hits this wall. (Actually, I did find that in the manual for 4.1 and 5 it states the max range is '-838:59:59' to őb:59:59' however, this was obviously not enforced in 4. :/ )

Time Query - Please Help?
I’m completely baffled by a query that I thought I had working yesterday, but I can’t get it working today.

Here’s the screnario:

I’m publishing a story to the web and I don’t won’t it to be published live until:

-The current date (type: date) is less or equal to now
-The current time (type: time) is less or equal to now

So here’s my query:

select * from cms_stories
WHERE section = 'news'
AND published_web_date <= NOW() OR published_web_date IS NULL
AND (published_web_time <= NOW() OR published_web_time IS NULL)
ORDER BY story_id
DESC LIMIT 1
Now the query works for the published_web_date, but not for the published_web_time. It seems to ignore that as you can see from the screenshot returned below from that query.


Query Time
Is there a function out there to determine the length of time a particular query took

Take Long Time To Run A Query!
I have a webserver that I just use for a webapplication. PHP, Apache and MySQL is installed on the server.

The size of MySQL database is 10 GB. End inn it is millions of rows.

I wonder where I search what is the normail time the data to return? In my case it takes from 20 sec to 2 min to run a query!

Time Query Question
I'm trying to pull dates from a db that are newer than 6 months old. I've been testing with 1 day, since there's nothing in the db that's older than 6 months.

query

PHP

$DATEsql = "SELECT DISTINCT DATE_FORMAT(time_in, '%m/%e/%Y') as time ";
$DATEsql .="FROM login ";
$DATEaql .="WHERE time_in > CURDATE() - INTERVAL 1 DAY ";
$DATEsql .="ORDER BY time DESC ";

that is giving me the same results as

PHP

$DATEsql = "SELECT DISTINCT DATE_FORMAT(time_in, '%m/%e/%Y') as time ";
$DATEsql .="FROM login ";
$DATEaql .="WHERE time_in < CURDATE() - INTERVAL 1 DAY ";
$DATEsql .="ORDER BY time DESC ";

This is what I'm interpreting as what I need to do according to the MySql manual.

How To Get Time Execution Of A Query?
Do you know how to get the time that a query executes? Is there a formula on how to get it?

Example:

Note: I have 5000 data in the table cars

$result = mysql_query("Select * from cars");

Question: How to get time of executing the query above?

Execute Time Of A Query
I'm running a SELECT * query on a table with over 3,000 rows. I need to know the execute time on the query.

PHPMyAdmin shows it to me, but because they automatically add a LIMIT 0, 30 I suspect the time is only for those 30 records. It also has a feature to prevent web server timeouts that prevents me from setting the LIMIT to 0, 3100.

BTW, I'm programming in PHP. Does the time to run the query get automatically passed when PHP sends the query to MySQL?

<? PHP
$Query = "select * from my_table where 1";
$Result = MYSQL_QUERY($Query);
?>

Using Time Functions Within A Query
I'm currently working on a script that searches through a database of restauarant information. One of the things it does is allow the user to search only for restaurants that are open at the time of the search, however i get errors when trying to implement this.

Here is the query im using:

How To Get Query Execution Time
How to get query execution time in "mysqlquery.log" files

I am using:

Linux 7.3
mysql 4.1

How to display the query execution time for each and every query in log files.
i have configured "slow-log-query" and "mysqlquery.log" in "my.cnf" is pasted below.

log = /var/lib/mysql/mysqlquery.log
log-slow-queries = /var/lib/mysql/slowquery.log
long-query-time = 0
slow-launch-time = 1

then i can get a output in "mysqlquery.log" like,

070830 9:24:29 2 Connect root@localhost on
2 Init DB jbdatabase
2 Query select count(*) from vacancy1_table
2 Query select category,listcategory from category_t
able order by category
2 Quit


but i need to display the "timetaken of each end every executed query" along with the query in the above logfile like,

E.g:select category,listcategory from category_table order by category(0.03 secs).

Query Execution Time
I am using mysql for my shopping site,Performance of site very slow then I used mysql_stat php function to find out howmany slow queries,it shows 20.

Now my question is any function in mysql(or)PHP to show 20 slow queries.

Limiting Query Time
Is it possible to limit the query time in MySQL (3.x or 4.0)? For
example, I'd like to have any query that takes more than a specified
number of seconds just quit automatically. Seems dumb, but on a web
site, nobody is going to wait minutes for a query to return so they
refresh anyway. So on a busy server, MySQL ends up with several queries
running that all take a long time to finish which compound to make it
even slower. A simple time limit would solve the problem. Yes, I know
that the queries should take less time, but again, on a busy server,
sometimes the longer queries do take a long time (10 minutes or more)
to complete.

Last Query Execution Time
Is there a way to retreive the elapsed time for the prevously executed query?

Alternatively, Is there a way to query the current time in fractions of a second?

I am attempting to use a stored procedure to execute and track the time it takes to run some queries and other commands.

The logic of the stored proc would go something like this.....

Average Time Query
I have come stuck with averaging a column with type of Time.

I know there is a function AVG() that I can use to filter the average of a column, however, this brings back an integer.

Is there any way to return the average in time format (IE 00:00:00)?

BACKGROUND INFO:

SELECT `estimatedTime`
FROM job_sheet;

Returns,

01:00:00
21:30:00
01:00:00

The data type is time, and the default is 00:00:00.

Exceeded Run Time Query
I made a application in PHP, I have a table "control1" and this table have 85000 registries and Size is 200 MB, so when I try do a query in PHP, I have a error "exceeded run time", I changed the time but is the same, and after I connected by console, and I could see that the query take 14 minutes.

Here my sql:

$sql_filtro="SELECT COUNT(*) nFilas FROM control1 WHERE MATCH (contenido) AGAINST ('$q')";

Add Time Using A Select Query
Hello, how can I add, say, 2 hrs from a time in a database using a select query. I have searched the forums but cannot find an answer. Is it possible PHP Code:

 select 
date,
`time`                         as timetime
     , time_format(`time','%l:%i %p') as Printtime,
client,
address
from.......... 

Query Execution Time
I am interested in displaying the query execution time as mysql does from the console, but using php. I've looked everywhere for this and can't find anything. Does anyone know how to display this information to the browser via php? The information must be there since the console provides it.

I checked the php function mysql_info(), but that only shows records, duplicates, deleted, matches, changed, warnings, etc. Didnt see any specific php function for getting execution time.


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