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


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Mysql Select Based On Datetime


I am having an issue returning a known record based on a date field that is of datetime format from mysql.

the data looks like this in mysql: 2006-01-26 20:01:45
here is the eror I receive:
SQL error=You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ཐ:01:45' at line 1

this is the select statement I am using

("SELECT selections from your_show WHERE userid = $userid and date = ".rawurldecode($date)." ");
$date is passed as 2006-01-26%2020:01:45




View Complete Forum Thread with Replies

Related Forum Messages:
MySQL Select By Datetime?
Just moving my web site ( in ASP ) over to MySQL from Access,

and I'm having trouble with this query:

strsql ="select count(*) from transactions where transactions.BAdateStamper between #" & theMonth & "/" & i & "/" & theYear & " 00:00:01# and #" & theMonth & "/" & i & "/" & theYear & " 23:59:59# and active=1"

was hoping that someone might know what I'm going wrong here,

View Replies !
MySQL Select Datetime Less Than Or Equal To
I am using MySQL 4.0.18 and I have a field named "order_datetime" in
which I store data in the format 20041001 23:00:00 (for example Oct 1,
2004 11pm)

When I do a select statement to find dates in a given range, the
result set never includes records that have the ending date. For
example, if my SQL statement is

Select * from HH_Will_Call where (order_datetime >= (20041001) and
order_datetime <= (20041003)) order by order_datetime

It will only include records through Oct 2, even though I know there
are records in the table that have Oct 3!

As you can see, I am using the less than or equal to operator, yet I
have this problem with any date range. How can I get the ending date
to be included?

View Replies !
Generating DAILY Min&amp;Max Over A Period Of Time, Based On A "DateTime" Field
how to print the minimum and maximum of a specific field, between two datetimes (both having the time 02:00:00) - so I did this:

WHERE ((tblvalues.dtLPDateTime)>="2006-01-01 02:00:00" And (tblvalues.dtLPDateTime)<"2006-01-03 02:00:00"))

Now I want to print those min and max values but for each day in this cycle, i mean, for this example, there would be two records like:
Day Min Max
2006-01-01 02:00:00 -> 2006-01-02 02:00:00 | 40 | 59
2006-01-02 02:00:00 -> 2006-01-03 02:00:00 | 49 | 68
where at this point i`m getting min=40 and max=68

View Replies !
Select Based On FK
I have two questions regarding the MySQL v4.1.16 scenario below:

1. What should the FK on update and on delete parameters be (i.e., default, cascade, restrict, no action, etc.)?

2. How can I insert the correct id’s as implied below?

I have tried just about everything (including “Insert …select”, “LAST_UPDATE_ID();”, etc.) and whenever I think I am starting to get close I either get more errors or ‘0 records added’ with no error message;

I would greatlyappreciate someone who could instruct me on how to accomplish this task.

View Replies !
SELECT Based On 2 Tables
I'm writing some custom stuff to pull from a WordPress install I have one one of my servers.

For one function I want to SELECT all the rows from one table based on criteria from that table and another table (they are related by the row ID of the first table). Here is the SQL I have now....

sql Code:
Original
- sql Code

SELECT DISTINCT t2.* FROM wp_term_relationships AS t1, wp_posts AS t2 WHERE t1.term_taxonomy_id = '4' AND t2.post_status = 'publish' AND t2.post_type = 'post' ORDER BY t2.post_date DESC

SELECT DISTINCT t2.* FROM wp_term_relationships AS t1, wp_posts AS t2 WHERE t1.term_taxonomy_id = '4' AND t2.post_status = 'publish' AND t2.post_type = 'post' ORDER BY t2.post_date DESC

It seems to be returning too many results. It's just returning all the rows from wp_posts that match the post_type and post_status criteria and ignoring the term_taxonomy_id (from wp_term_relationships) requirement.

View Replies !
Select Based On Rarity?
I have a table and one column is titled "rarity." Every once in a while, ONE random row from this table will need to be selected... I want to select the random row based on the rarity column. All of the rarities would equal 1. For example, a rarity of .38 would have .38 probability of being selected from the table.

View Replies !
Select Datetime
i am getting started with some development for work, and i need to know how to select a time that is exactly 24 hours ago.
in the history table of my database, i have a datetime object formatted like this
2005-10-23 09:23:54
about 20 or so records going in there each day, and i need to find the value of this time yesterday. i looked at the mysql docs and reference manual, but it is a bit cryptic.

View Replies !
SELECT Based On All Day Names And Their Hours
I have a table which has a DATETIME column which stores datatime for each record.

I wanted to calculate the total/average of the records for each day and then for each hour of that day ALL TIMES like not only the current week or current month or year but for all available records.

a sample output can be

Monday
00 (count value)
01 (count value)
02..... (count value)
23 (count value)

Tuesday
00 (count value)
01 (count value)
02..... (count value)
23 (count value)

...

Sunday
00 (count value)
01 (count value)
02..... (count value)
23 (count value)

I tried something like following

SELECT count(id) as cnt,HOUR(hitdate) as hr, hitdate FROM hits GROUP BY DAYOFWEEK(hitdate),HOUR(hitdate)

And I am getting the following results, (long result)

cnt hr hitdate
1274 0 2008-07-27 00:00:50
1235 1 2008-07-27 01:00:07
921 2 2008-07-27 02:02:13
830 3 2008-07-27 03:00:03
674 4 2008-07-27 04:02:49
617 5 2008-07-27 05:00:37
606 6 2008-07-27 06:01:41
545 7 2008-07-27 07:01:52
534 8 2008-07-27 08:05:58
630 9 2008-07-27 09:04:01
680 10 2008-07-27 10:04:41
688 11 2008-07-27 11:01:26
881 12 2008-07-27 12:00:22
745 13 2008-07-27 13:00:09....

View Replies !
Select Columns Based On Subselect
Is it possible to do the following:

select (select from factors where type='factor_1') from survey_results where last_name='some_name';

I get the error: "#1242 - Subquery returns more than 1 row"

Can I convert the rows to a list?

More info if needed:

I have two tables, 'factors' and 'survey_results'. A survey_result row contains a list of factors (> 30). Factors can have different types. For a survey result I'd like to select only the columns related to a certain type of factor and analyze just those factors (e.g., find the min and max scores). I don't want to hard code lists of factors of certain types to use in my outside select statement. I'd like to do it dynamically based on the factors table.

View Replies !
Select Statement Based On Bytes
I have a table with an attribute named "message" with a varbinary type in which information is being stored in. It contains a total of 10 bytes and I want to select ONLY bytes 4-7.

View Replies !
Conditional Select Based On Query Results
I want to print a different message on the database, if a query returns an empty set and a different if the query returns any records. How can i accomplish that? I looked at the case statement but i can't get it working with that.

View Replies !
Select And Return Based On The Relation Of Two Other Tables
I'm learning mysql and am looking for an example of how to do a certain type of search.

I have three tables and I'd like to pull records from one and order them based on the relation of two tables. My tables are: ....

View Replies !
Select Record Based On 'change' Date
I currently have a database containing a table with the following fields:
signid, sign_typ, changedate and time.

The 'changedate' field is the date on which the star sign changes and becomes 'active' until the next 'changedate' in the table. I am trying to search this field by a date the user enters and display the 'sign_typ'.

View Replies !
Select Based On Two Rows In Mapping Table
I have a many to many relationship between a resource and tag:

resource - 1:M - tagged_resource - M:1 - tag

So a resource can have many tags and a tag can belong to many resources. The data would look like this:

RESOURCE TABLE
id: 1
name: resource1

TAG TABLE
id: 1
tag: new
id: 2
tag: tested

TAGGED_RESOURCE
resourceID: 1
tagID: 1
resourceID: 1
tagID: 2

How can I select the single row from the RESOURCE TABLE which has the tags 'new' and 'tested' in the TAGGED_RESOURCE TABLE?

I have tried using 'IN' but it acts like an OR operator rather than AND.

View Replies !
Difference In SELECT WHERE IN With Datetime Fields
Anyone can explain the following?

Table definition:

CREATE TABLE testdate
(
SalesDate DATETIME,
SalesTotal DOUBLE,
PRIMARY KEY (SalesDate)
)

If I use the following SQL statement I get results:

SELECT * FROM testdate
WHERE SalesDate = '2003-08-27' OR SalesDate='2003-07-27';

But I get an empty set when I use this:

SELECT * FROM testdate
WHERE SalesDate IN ('2003-08-27', '2003-07-27');

This happens on both 4.0.15 and 3.23.57.
But the above statements work the same under Microsoft SQL Server.

Why is MySQL interpreting WHERE IN and WHERE = OR = differently?

View Replies !
Select Julian Day From Datetime Field
I am trying to build a SELECT query that allows the user to pull a specific day from a table of data. Currently, I have a year, day, and time field, so the user can SELECT * from TABLE where year = 2006 AND day = 245.

I'm dropping these three fields in exchange for one datetime field (with the format yyyy-mm-dd hh:mm). Now when I select day(datetime) = 245 no records are found because I suspect that the days are being counted as 1 - 28, 30, and 31. Is there a simple way around this like a julian day function that is included in the SELECT statement?

View Replies !
CREATE Tablename Based On Result Of SELECT Statement?
Is it possible to have an CREATE statement that contains a SELECT in the section of the CREATE that specifies the TABLE?

I want to have a sql script that can execute SELECT YEAR(CURDATE()) and SELECT MONTH(CURDATE()) to give me the Year and Month and then use these to create the Table Name: tbl_MetaData_2008-03

Example:

CREATE TABLE tbl_MetaData_X-Y
( ...

Where X is the YEAR and Y is the MONTH

View Replies !
SELECT, DATETIME And Checking Result Counts
I would be very grateful if someone would help me a little bit in my first attempts to use MySQL for my needs.

I have a table with several fields, and a DATETIME field.
I want to:
SELECT data according to these rules:
1- The last active 5 hours worth of data (by active, I mean hours which has at least one data line according to DATETIME)
2- Sort by DATETIME as the first key, latest at the beginning of the output, and order by other fields as supplemental keys

The only way I found yet is to make multiple SELECT queries, one for each hour. And I don't know how to check for active hours, depending on the count on the results of the SELECT query.

Is it possible to use the result of a SELECT, and output one particular field separately without doing another SELECT within MySQL?

View Replies !
Get Back The Date Part Of A Datetime With A Select
My web site uses the same request, on one hand, to make selections at precise hours, on the other hand, to make selections for day:

SELECT thing FROM `table ` WHERE dates = ' 2008-01-01 09:06:40 '

The daily table `table ` contains a column date in the format "date" (YYYY-MM-DD).

With my former version of Mysql (5.1.14-beta), all the lines containing date = '2008-01-01' were selected.

My problem is that since I've changed my Mysql version these are lines like date = ' 2008-01-01 09:06:40 ' which seem to be selected : so nobody in my daily table...

Is it a problem of version of Mysql? Nevertheless my newone version is more recent (5.0.51a-6) than the former.Is it possible to select lines having '2008-01-01' without modifying my SELECT?

View Replies !
ORDER Based On One Field But LIMIT Based On Another?
Say I have a table with students and their grades, and I want to get the students with the top 10 grades, but the result to be sorted based on their name. How would I do that?

View Replies !
Compare Datetime Field With Todays Datetime
How do I compare a datetime field in the database with todays datetime...

Is it:

if rs("fieldname")<>getdate() then
....
else
(gotto set a cookie here)
end if

Somebody suggested I use cdate...what is tht for..is it to make sure they are both in the same format or something.. if so how do I use it?

View Replies !
Select Data From 1 Table Based On Criteria From Another Table
is it possible to select all the data in one table based on a criteria from another table?

for instance i want to select all the therapist from massage_therapist WHERE massage_schedule.finish > 0.
i don't want merged results. i just need to list all therapist based on the where criteria from a different table.

these two tables have the therapist_id in common.

View Replies !
User Based PHP W/MySql
If I were to take a few different (gpl released) php programs that use MySql databases for the user data, could I integrate all the users into one database?
For instance, a user signs up in one of my forums, and their info is stored in a database. Then if they go to my auction script using the same database, they don't have to sign up again.

My guess is that yes it would work, but I'd have to go through each php file and edit where it called for the table data in each database to point to the same places.

View Replies !
Web Based MySQL Editor
I am looking for a Web Based MySQL Editor to manage, database, users, etc and if you can, tell me why you like it, good points, bad points, etc. I use PHPMyAdmin right now, so I am looking for something possibly better.

View Replies !
MySQL Datetime
I'm trying to set up an RSS 2.0 feed and in order for it to be vaild I need to convert a datetime column in my database to an RFC-822 date-time (Wed, 02 Oct 2002 08:00:00 EST).

I'm using the following SQL, but am returning NULL in the date_format column from the query:

SELECT article_id AS id, article_title AS title, article_deck AS deck, DATE_FORMAT( 'article_date_added', '%a, %d %b %Y %T' ) AS date_format
FROM article
WHERE article_id =24 LIMIT 0 , 30

View Replies !
File Based Version Of MySql
I would like to create a program in C# and use MySql as a backend. Is there a file based version of MySql that does not require the server to be installed. I know that if I use a Ms Access db, I can manitpulate the data without the user having Access installed (using ADO). I want to know such a thing exists for MySql?

View Replies !
DateTime Format In MySQL
i have datetime format in mysql database table. now,
in mysql date is YYYY-MM-DD format. how can i insert date in this
format with VB Script ? i had tried following

dim dt, dy, dm, dd, pd, tm
tm = Time
dt = Date
dy = DatePart("YYYY",dt)
dm = DatePart("M",dt)
dd = DatePart("D", dt)

pd = dy & "-" & dm & "-" & dd & " " tm

this shows correct datetime, but doesn't insert in database table. it
gives error: incorrect format.

View Replies !
Mysql Datetime Columns
I've been storing my times in an integer field as unix timestamps. I'm thinking about making the switch to mysql's date/time column types instead but I have a question.I do a lot of comparing with dates and was wondering if using mysql's date/time column types will slow down my queries since it has to convert the column to an "internal long integer" to do a comparison rather than not just comparing straight integers with a unix timestamp in an integer column.

source: http://dev.mysql.com/doc/refman/5.0/en/using-date.html
Quote: Originally Posted by mysql.com When you compare a DATE, TIME, DATETIME, or TIMESTAMP to a constant string with the <, <=, =, >=, >, or BETWEEN operators, MySQL normally converts the string to an internal long integer for faster comparision (and also for a bit more relaxed string checking).

View Replies !
Perl And Mysql Datetime
I am trying to have an update form for a datetime field. I've been looking all morning and haven't been able to find any examples of how to do it.
I have the date in the form formatted by perl like this: 08-14-2006 11:29:28 and when I do the update to mysql nothing happens. It does not work.
I need to make it so the user can put the time the student left.

View Replies !
Unixtimestamp Or Datetime From Mysql?
i'am designing a database and one question occurs evertime i need a time attribute: should i use int with unixtimestamps or the mysql datetime? my associate says unixtime stamp is far better when it comes to calculations with time.

on the other hand i read something about new functions in mysql 4.1.1. relating date and time. do i need unixtime anymore for any calculations if i would use mysql 4.1.1.?

View Replies !
MySQL Datetime DataType
I'm just trying to insert a datetime value into mysql datetime feild, but everytime run the script, and then look in the data base all i see is 0000-00-00 00:00:00

sql= "INSERT INTO ForumPosts (PostDate) VALUES ('" & NOW() & "')"
set rs= MyConn.execute(sql)
set sql= nothing

View Replies !
DATETIME Field Conversion In Mysql
I know that there is a function in MYSQL to define a 'datetime' type column but when I am migrating a foxpro database to MYSQL type and when foxpro has the datetime column in the format: "08/12/1999 09:39:00", how would I convert this to mysql format while I am trying to load the data in the database(using LOAD command).

I have used str_to_date functions in the past to convert the date formats between the two databases but how do we go about the datetime format.

View Replies !
Connecting To Remote Mysql Server Using Web Based Php Script
I am trying to setup wordpress software and trying to connect to mysql database located in remote host. I kept getting an error saying that 'we can't connect to database server specified in DB_HOST field of php code'

how to make wordpress software's remote connections to mysql server located in a remote host

View Replies !
What Is The NOW() Function In A MySQL DateTime Field Query?
I have a monitoring script which I am trying to better understand. One of the queries is built as follows: .....

View Replies !
What Is Execution Time Of A Query Based On? (was "a Mysql Question")
when selecting data from the database, does the time taken to retrieve it vary from 56k connections to T3 connections? or does it all depends ont he general server speed/amount of connections on the db?

im not sure if ive explained that in the best way for people to understand
but im sure someone will get what i mean

View Replies !
Using A Web Based Database
My web site host allows me to create MySQL databases on its database server. I've created a database as a trial. Now I would want users of my website to supply data to the database and for me to be able to extract it for analysis.

View Replies !
Web-based Chat
I'm debating between 2 different table setups for a web-based chat system (gchat clone). The first is just one table labeled 'chat' which has the columns 'user_1' 'user_2' 'time' 'message'. The second would be dynamically creating/deleting tables with the user names as table names like 'user_1/user_2'. I don't know a whole lot about DB table organization but I was thinking the actual 'select' statement would be faster with seperate tables. Any ideas?

View Replies !
Datetime Value
I need to return a datetime value like this: yyyy-mm-dd hh:mm:ss. The question is, performance wise, would I be better off storing the datetime value in a datetime column which takes up 8 bytes, and returns the data directly, or would I be better off storing it in an INT which takes 4 bytes, and then when selecting it do: from_unixtime(columnname)
Which would be the better choice?

View Replies !
DATETIME And UTC
I am currious does anyone know if I have a DATEIME Column if I can pass it a UTC and have it work properly. (not at a place I can test it at would love to know before I am).

So pass 1124908190.99 and have it in the DB as a DATETIME.

View Replies !
Datetime Now
in Mysql Control Center I have created a column DateTime
the default value shown is 0000-00-00 00:00:00

I have try to change it by now but it doesn't work
how can you get automaticly the current time?

View Replies !
Need Help With DateTime !
I have a table i.e. Schedule and it has a datetime column i.e. Start and it has the following records.

2007-11-21 08:55:12
2007-11-20 08:55:12
2007-11-19 08:55:12
2007-11-18 08:55:12
2007-11-17 08:55:12
2007-11-16 08:55:12

If the current date time is "2007-11-19 08:55:12" how will I come to know what is the very next date that is greater than this? and what is the very previous date that is less than this datetime? Technically speaking what statement/query may I use to get this?
In this case "2007-11-20 08:55:12" will be the very next date and "2007-11-18 08:55:12" will be the previous date.

View Replies !
DateTime
How do I insert the current date and time into a DateTime column using an SQL INSERT INTO statement.

View Replies !
UPDATE Based On Value In Another Table
How do I update a table to remove orphaned references to a second table? I've deleted rows in the second table, which has a unique auto_increment key. The first table now has references to keys that no longer exist. I need to update the first table, setting the value to NULL where the referenced key no longer exists. Something like:

UPDATE table1 SET table2ID = NULL WHERE table1.table2ID NOT FOUND IN
table2.ID;

The NOT FOUND IN isn't SQL, of course, but I'm not sure what should go there.

View Replies !
Union Based Upon First Query
I have a query that I would like to use a union statement in to grab the number of replies to a specific thread. The initial topic thread is in a different table, which I am grabbing in the initial query... I would prefer to do this in the single query, however I supposed I could do a separate loops and grab the number of replies with a totally distinct query ....

View Replies !
Syntax Based On MS Access SQL
Our shop is using an old version of MySQL (3.23).In testing our database concept we put together a test database in Access and the sql statement in MS Access looks like

SELECT DISTINCT FROM table1.col1, table2,col1
FROM table1, table2
WHERE (((table1,col1) like "*" & table2!col2 & "*"));

this gives us output from both tables(tables1 and tables2) while looping over the values of table2.col2.How does MySQL do this type of function?

View Replies !
Items Based On The First Letter
we have products database with CD's, and would like to create an alphabetical list of artists, then display the CD's that the artist has underneath them.
The database has the products in them, with the artists name being called 'prod_artist_name'. the query i tried, though I knew it wouldn't work is:

SELECT *
FROM products
WHERE prod_artist_name LIKE '%n%'

Now, this displays all the artists with the letter 'n' in their name, obviously. just wondering if there was a way to display the artists with 'n' as the first letter of their name.

View Replies !
Rows Based On First Letter
I'm trying to figure out the fastest/best way to return rows based on the first letter of the title column in my table. For example, I want to get all the article titles that start with the letter "a".
Is there any difference between the two select statements? Any reason to use one over the other? Memory? Speed?

SELECT title FROM table WHERE LEFT(title, 1) ='a';
or
SELECT title FROM table WHERE title like 'a%';

View Replies !
Sql Vs Text-based Databases
currently my site is storing data in text files, using explode() and seems pretty fast to me. would mysql be faster? i have a second box where i could set it up.

View Replies !

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