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.





Date And Unix Timestamp Comparison


i have a field in my database called 'release' that contains a date in the format YYYY-MM-DD, except its stored as text and not in the date format.

I need to exclude certain results from my query based on how recent it was released and im having a hard time.

ive been trying to use this...

SELECT title FROM products
WHERE release< FROM_UNIXTIME(unix_timestamp(now()) - 183*86400,'%Y-%m-%d') ;




View Complete Forum Thread with Replies

Related Forum Messages:
Search MYSQL Date Column With Unix Timestamp?
I want to search for records that are ON or After a certain date in a column that uses MYSQL date form (yyyy-mm-dd) with a unix timestamp.

View Replies !
UNIX Timestamp
How do I get a UNIX timestamp in MySQL?

View Replies !
Using CURDATE With UNIX Timestamp
I have a table where the dates are stored in UNIX timestamp format. I'm trying to use the CURDATE term for a select query but it isn't working. Does CURDATE work with the UNIX time stamp?
Any help is appreciated.
here's the query:
select first_name, last_name, date_expires, title
from cl_member, `user`, cl_chapter
where cl_member.user_id=`user`.user_id
and cl_member.chapter_id=cl_chapter.chapter_id
and cl_member.chapter_id=14
and month(date_expires)=month(CURDATE())
ORDER BY last_name

View Replies !
Covert Unix Timestamp
Been trying to use DATE_FORMAT on a timestamp in my table. However, just noticed that it's a UNIX timestamp, and not a datetime() timestamp. Is there a function that convert unix timestamps in a sql statement?

Trying to get the format "dd/mm/yyyy"


View Replies !
Unix Timestamp Select Query
I am having trouble with the following sql query.I am trying to select all records in the future where the date is greater than today but to include today, the date field in the db is an unix timestamp.


Code:

"SELECT * FROM mysqltable WHERE mysqldatefield > now()-1 ORDER BY mysqldatefield DESC"

View Replies !
MySQL Generate UNIX Timestamp
Cam MySQL create a UNIX timestamp during an INSERT? I want to create a timestamp that is the number of seconds since January 1st 1970. Are there any inbuilt functions for doing so?

View Replies !
Inserting Current Unix Timestamp
I am working on coding a query to generate a phpBB useraccount in the mySQL database.

INSERT INTO kylebt_Forums.phpbb_users SET `username` = '%username%', `user_password`=MD5('%password%'), `user_email`='%email%', `user_regdate`=''

The user_regdate field is giving me problems as far as accepting the 10-digit unix_timestamp();

Apparently phpBB reads the PHP command time() however I am not sure how I need to implement this in the above code to have the timestamp show up correctly in the mySQL table. Currently, the user_regdate is showing up as the default value of '0'

View Replies !
Can't Insert A Unix Timestamp Into Mysql
Just upgraded to 4.1.8 and when I create a field with a date value (field is trdate), it always has default of 0000-00-00. And when I insert values with unix timestamp values (which I prefer, and they come from php's strtotime function),the record does not insert properly. I tried to set, through phpmyadmin, unix/current timestamp and to no avail.

If I use a strtotime php function to convert a date into a timestamp, what is the proven way to make sure that value is saved during inserts? I am on the mysql manual, searched this board, but nothing works.


View Replies !
Comparing Dates If One Is Unix Timestamp
I'm building a simple cms and i'm trying to get something done.. I store the dates as UNIX timestamps. However i want to add a feature let's say to display how many entries have been posted today. Something like [Articles posted today: 3]

View Replies !
TIMESTAMP Operations & Comparison
I'm trying to write a query that will remove all entries older than 30 days, using MySQL 5. The date is stored as TIMESTAMP.

I'm stumped on just how to express "30 days earlier than now". I'm familar with the NOW() function but don't know how to add/subtract dates.

The query is otherwise very simple, something like
DELETE FROM posts WHERE datecreated < [????]

View Replies !
View The Timestamp In MySQL As The UNIX By Adding 0 To The End Of The Row
i've read that in MySQL 4.1, you can view the timestamp in MySQL as the UNIX by adding 0 to the end of the row. Can someone help me modify my code so that this same idea will also in my code?

<tr><td colspan="2">
<?php $datetime=$row["time" + 0];
$year = substr( $datetime, 0,4 );
$mon = substr( $datetime, 5,2 );
$day = substr( $datetime, 7,2 );
$hour = substr( $datetime, 9,2 );
$min = substr( $datetime, 11,2 );
$sec = substr( $datetime, 13,2);
$orgdate = date("l F dS, Y h:i A",
mktime( $hour, $min, $sec, $mon, $day, $year));


?>

<b>Date:</b> <?php echo $datetime; ?></td></tr>

View Replies !
DATE COMPARISON :: Get Older Date Between Two Dates
I was wondering if there is a date function to get the older date between two dates?. Or smething that indicates me that one date is older than the other one.I know that I have the function YEAR,MONTH,DAY and I can use them, but I don't know if exists a function that can do the same.

View Replies !
Unix Date Problems
1) I was investigating the unix_timestamp routine in mysql (version
3.23.46-nt) and for some reason the unix epoch (1-1-1970) was returned
with a value of -3600. Then, as you can see, it suddenly corrected
itself. I can't replicate this error, but it caused me to shudder.
Attached is the output from the command line client.
2) The function from_unixtime(n) wraps on my server after 2^31 seconds.
e.g. select from_unixtime(2147483648) returns "1900-01-00 00:00:00". I
suspect this is caused by the underlying time_t size that mysql was
compiled with. Is this so? Are any versions of mysql compiled with a
larger time_t?

+---------------------------+
| from_unixtime(2147483648) |
+---------------------------+
| 1900-01-00 00:00:00 |
+---------------------------+
1 row in set (0.00 sec)


mysql> select unix_timestamp();
+------------------+
| u................................

View Replies !
Selecting By Unix 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?

View Replies !
Date Comparison 2
I want to compare dates in sequential records (in mysql format YYYY-MM-DD) in a db. I have a loop to iterate through a set of records. In this loop, how can I refer to the previous record in the loop?

As in:

for ($i=0; $i <$num_results; i++) {
$row = mysql_fetch_assoc($result);
if ($row('thisDate') != the previous record's date) {
do something
}
}

View Replies !
Date Comparison Trouble
Spent the last 30 mins looking for a solution and haven't found one so:
The table looks like:

ID
aDate
Days - days in advance

1 | 2008-03-10 12:00:00 | 7

Im trying to do the following:
SELECT table. *
FROM table
WHERE aDate >= '2008-03-(03+Days) 11:30:00'

Basically so i can feed a date and it uses that date plus whatever is in the days fields, simple i know!

View Replies !
Date Comparison Problem
I have a website with a diary of events. I have just come across this problem:

The diary is listed on the site month by month - you can click a month and events for that month will show up. Events have a from date and to date and can span across multiple months. This has all been working fine until I added an event running from december 06 to january 07 - it no longer showed up. Here is how my query looked:

(using december 2006 as the selected page as an example)



SELECT * FROM diary WHERE (MONTH(from_date) <= MONTH(&#55614;&#57158;-12-01') AND MONTH(to_date) >= MONTH(&#55614;&#57158;-12-01') AND YEAR(from_date) = YEAR(&#55614;&#57158;-12-01')) OR (MONTH(from_date) <= MONTH(&#55614;&#57158;-12-01') AND MONTH(to_date) >= MONTH(&#55614;&#57158;-12-01') AND YEAR(to_date) = YEAR(&#55614;&#57158;-12-01')) ORDER BY from_date, to_date
Now looking back it is obvious that this will not work as it is looking for a match in the years. After some research and trial and error I have come up with the following query:



SELECT * FROM diary WHERE (UNIX_TIMESTAMP(&#55614;&#57158;-12-01') BETWEEN UNIX_TIMESTAMP(from_date) AND UNIX_TIMESTAMP(to_date)) ORDER BY from_date, to_date
However this is still not working.

This is really bugging me and any help will be greatly appreciated.

Thanks!

View Replies !
Fake Date Comparison
Code:
select * from tareas where STR_TO_DATE( fecha, '%d/%m/%Y' ) = STR_TO_DATE( 19/11/2007, '%d/%m/%Y' )' order by STR_TO_DATE( fecha, '%d/%m/%Y' ) DESC

Yes, an operator wrong, but why ?

View Replies !
GROUP BY Date With Variable Is Unix Time
I am saving the Unix time every time a record is created in a field called "Time" and would now like to write a report to group on Date ... is there a in-built function to do this ..

SELECT * FROM tblTemp GROUP BY [Date] ?

View Replies !
Date Comparison Not Working (dammit!)
My date_added field is a DATETIME
mySQL 4.1.10

I'm trying to get any record that was created over 72 hours ago and has not activated their account.

PHP

SELECT fname,email,uname,passwd FROM customers WHERE date_added >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 72 HOUR) AND activate = 0

That dog just don't wanna hunt. NULL is returned. The query returned in phpmyadmin is

PHP

SELECT fname, email, uname, passwd
FROM customers
WHERE date_added >= DATE_SUB(
CURRENT_TIMESTAMP , INTERVAL 5 MINUTE )
LIMIT 0 , 30

I never signed up for a limit!

And, while I have your attention I want to do the same, except get any record that has been active for 27 days (got to send an email, because I'm gonna dump their a$$ on day 30!)

View Replies !
Date Vs Timestamp
I have a somewhat large table (about 900,000 rows). I regularly need to run many queries against this table and it's is rather slow. Before making any major changes, I wanted to confirm whether the following changes would help.

Right now, I run a query like this:

SELECT count(*) FROM refer WHERE date >= '$date1' AND date <= '$date2'

However, "date" is actually of type timestamp. So I have an index on the field, but it has the same cardinality as the number of rows, as you might expect. I've also heard using a reserved word of 'date' can be a problem, but not sure if that's a performance issue.

I think I may occasionally still need this level of granularity for some things, but 99% of the time, I really only need the actual date for my SELECT statements. I'm thinking it might be best to create a field2 that is of type date and use that for the queries, with an index, and drop the index on field1 altogether.

The more I think about the more I'm convinced the way I'm doing it now is the reason it is so slow. Can someone please confirm my stupidity?

View Replies !
Timestamp :: Registration Date
As a newbie to MySQL and PHP, I have been able to set up MySQL as test server on my MacOS X and have also succeeded in connecting my test sites registration form to the proper table in MySQL.
Everything works fine except getting MySQL to insert the registration date/time automatically as a new record is posted. I have created two "Timestamp"-date columns - the first one for "Change date" and the second for "Registration date". According to what I can gather from reading, this should do the trick, but it doesn't. No date or time is inserted in the registration date field.
Can someone explain (in newbie terms) what I am doing wrong and what I should do to make it work? I want the registration date to be filled-in automatically in every new record and then stay unchanged even if other parts of the record are changed.

View Replies !
Where The Date (timestamp) Is Greater Than Now
On my site I want to output all records in my database with two conditions

Where the date (timestamp) is greater than now but within the next 7 days?

Can anyone help? I've got a feeling I need to use interval, but not sure?

View Replies !
How To Get Just Date To Display In Field When Using TIMESTAMP?
I would like to capture the date and time in a field for each record. I know that using TIMESTAMP and default value of CURRENT_TIMESTAMP returns the full date and time but I only want the date displayed in my webpage table when displaying the records. Should I be using something else other than TIMESTAMP or is there some parameters I can use to do this?

View Replies !
TIMESTAMP :: Query By Time And Date
I have a field in my table that holds a timestamp. Below is a pseudo-query to describe what I would like to do.

SELECT * FROM `mytable` WHERE `saved_date` <= `6/24/05 10:22:34 AM`

`saved_date` is the field holding a TIMESTAMP. If anyone could give me the query that would actually do what I am trying to do above,

View Replies !
DATE / TIMESTAMP Default Values
im is having problems with auto inserting date in my table.

I dont know what is the default value i will set if column type to DATE. It was succesful though if is use the TIMESTAMP type in the column and is using CURRENT_TIMESTAMP as the dafault value. mysql automatically inserts the current date and time to the database everytime a new record is inserted. The problem with using TIMESTAMP is that i only want the date and not the additional time.

Is there a default value I can use for the DATE function instead of using TIMESTAMP? I already tried NOW(), CURDATE(), CURRENT_DATE() to no avail

View Replies !
TIMESTAMP :: Creation And Update Date
I want to create an auto creation date and update date in my mysql table. I am using the "MySQL Cookbook" approach, using the TIMESTAMP field which basically is:

- create 2 new fields in the table (t_create and t_update)
- both NULL
- when a new record is created they both will register a common timestamp
- when the record is modified the t_update will change, but not the t_create

View Replies !
Select Where Date = Today Timestamp Field
I have data stored in mysql table with a field (date), the data stored inside the field (date) is timestamp, how can i select data from this table where date = today (Current Day) ?

View Replies !
Transform Date To Mysql Timestamp Via CSV Import
I have a CSV file (from excel) with contains personal data, like names, adress, and birth date. The birth date is in this format yyyy-mm-dd. I would like to import this CSV file into my MYsql database with the "import CSV file" function that is build in PHPmyadmin.

The problem is that I need UNIX timestamps in my database, and not the date in yyy-mm-dd format. Code:

View Replies !
How I Can Change My Timestamp(14) To = Timestamp(8)
I am trying to find out how I can change my timestamp(14) to = timestamp(8).

View Replies !
Timestamp And Current_date/timestamp
Im stuck with a sql query.
Basically I have a db that stored a timestamp off everyone who has a successful login.
I want to be able to count all the people who have logged into today? How do I do that?

I thought the following would work but it didn't:

SELECT count(date) FROM nn_users_logs WHERE date = CURREN_TIMESTAMP

View Replies !
Using TCP/IP Instead Of Unix Sockets
An associate has asked me to take a look a problem he's having with starting
mysql. I thought I'd give it a shot to learn some more about mySQL before
having him turn it over to someone more knowledgeable than I. But I have to
ask here first.

Attempting to connect to the database via mysqladmin or mysql results in the
error (paraphrased) "Cannot connect to local database using socket
"/var/lib/mysql/mysql.sock".

That is the path to the socked specifiet in both mysqld and client sections
of the my.cnf.

mysqladmin -h `hostname` version shows that the Connection is via TCP/IP
rather than Unix Sockets.

Running on Redhat Linux AE 3 (I think)

/var/lib/mysql is world-writable-readable, but it is not owned by user mysql
(my next attempt to fix this)

/var/lib/mysql/mysql.sock is 777.

My question: What would be causing mysqld to be using TCP rather than Unix
sockets? I've checked permissions, verified settings in my.cnf (which is
very sparse... other entries are for logging), confirmed mysqld is running
and accessible via TCP/IP.

View Replies !
Md5 Comparison
UPDATE admin_users SET password = md5(?') WHERE id = 1;
SELECT password = md5(?') FROM admin_users WHERE id = 1;
The result of the last query is "0", which means the values don't match. How can that be? What am I missing? The hashes look just the same when I echo them. Is it a data type problem?

EDIT: I should mention the m5 password hash is stored in a binary(64) column.

View Replies !
Comparison In Db.
Don't know if it's even do-able in MySQL but I kinda think it is.

lets make an example table over a log.

day - action
1 ---- foo
1 ---- bar
2 ---- foo
2 ---- foo
2 ---- bar
2 ---- bar
2 ---- foo

Now I want, with one query, most of all, select the increase in percent and the name of the action that has increased the most from day one to day two. If this isn't possible I would like to select the name, the amount for the action on day one and the increase of the top increaser.

View Replies !
Comparison
I want to compare a text box value with the one stored in the mysql table. Here is the input of text box.

HTML Code:
352969678
and the mysql table record is like

HTML Code:
352 969678
a space is there after the first 3 digits. So i want to compare it via SQL.

Suppose that the data from the text box is in $data and the column in table is "phone" so i want to do this (in PHP):

HTML Code:
"select * from some_table where phone = ".$data
But it will not work as the data in the $data has not space after the first 3 digits while the record in table in database is having a space after the first 3 digits...

View Replies !
Unix Socket Vs TCP Mode
Our mysql database always run smoothness, but there have a strange question always happy.
We retrieve content using unix socket mode is always Correct, using TCP mode sometime will meet no return Error. What's wrong with TCP mode?

For example, We need to retrieve content from table Tab_Memo, the condition with ‘large’ is over 20KB, with ‘small’ is about ‘5KB’.

Using unix socket mode:
----------------------------------
mysql -u root -p password
1、select * from Tab_Memo where name = ‘large’; // The result is Correct.
2、select * from Tab_Memo where name = ‘small’; //The result is Correct.

Using unix socket mode
----------------------------------
1、select * from Tab_Memo where name = ‘large’; // NO result return.
2、select * from Tab_Memo where name = ‘small’; //The result is Correct.

View Replies !
Mysql Unix Client
I there, I would like to know if there is a mysql client that we can use from unix to connect to a mysql windows server?

View Replies !
TimeStamps In Unix-Format
In my database i have to work with timestamps in unix-format like '20070101000000' for 2007-01-01 00:00:00.

Now i have to look for the summary of the difference of two timestamps. The single difference of the timestamps are between one minute and about 15 hours. Now i don't know how to manage the correct sumary that should give me how many days, minutes and so on are summed.

View Replies !
MySQL Via Unix Sockets
I'm using java+JDBC connector. Where do I need to set up something to work with /var/lib/mysql/mysql.sock

View Replies !
Two Versions Of Mysql On Same Unix Box
I have mysql 3.23.58 version running on my unix box. I installed a new application on it which need mysql version > 4.0 so I thought of having two mysql versions running on the same unix box. I have first installation in /usr/local/mysql and I untared the new version in /var/local/mysql-standard-4.1.18-pc-linux-gnu-i686-glibc23.

I am following instructions given in http://dev.mysql.com/doc/refman/4.1/en/multiple-servers.html I also created a empty file and named it as mysql.sock.new and stored it in /var/local. When I try to start this new version from /var/local/mysql-standard-4.1.18-pc-linux-gnu-i686-glibc23 using ./bin/mysqld_safe --datadir=/var/local/mysql-standard-4.1.18-pc-linux-gnu-i686-glibc23/data & it says "A mysqld process already exists". Please tell me where I am going wrong and how to configure it properly?

View Replies !
Database Comparison
I am looking for some papers/information that compare relational
databases such as oracle, mysql, sql server etc. I am particularly
interested in their features such as locking mechanisms, integrity
constraints, views... Anyone know where I can find the information?

View Replies !
Text Comparison
I'm having a problem with one query. My database has the following
fields: id(int), time(int), and groupfield(enum - 5 possibilities). I
want to select all the rows where the time is between let's say 12 and
24 and the group is specified by the user using a html drop list. The
variable is named $group. Code:

View Replies !
Comparison Optimization
On to my problem. I'm running a query on a table with over 100,000 rows in it. Basically, my query is performing a "similar" check on books that people have logged in their "book list". It looks through the table and checks to see who has the most number of books similar to you. Here's the query:

select count(a.mem_id) as numMatches,m.username,m.mem_id as memberID from book_list a LEFT JOIN book_list_members m ON a.mem_id=m.mem_id where a.book_id in(224,164,30,43,47,1,6,52,90,45,120,270,...,2442) GROUP BY a.mem_id ORDER BY numMatches DESC LIMIT 50

In the in() comparison, this can be anywhere from 1 integer to 1000 integers, it all depends on how many books a user has in their list. I've indexed "book_id", but unfortunately if there are more than say, 100 elements in the IN() comparison, the query takes anywhere from 1-2 seconds to execute. That's a long time when I have hundreds of users hitting a website and running that query. Is there a better way to do this? Is there a way I can "store" this query result somewhere, and only have it updated every couple hours (cached in other words, for immediate access).

View Replies !
Float Comparison
I'm writing a simple database with one table and a few fields that lists some books. One of the fields is an Unsigned Float field that lists the book's reading level. Then I have a PHP/web page front end that users can search for books listed in the database.

Basically this is the probelm I'm having:
If a user asks for all the books between the reading levels 3.0 and 3.3 -- MySQL returns every record that has a reading level of 3 up to and including all the books with a reading level of 3.3. However, if a user types in the form they want all the books between 3.0 and 3.2 -- MySQL returns all the 3.0 and 3.1 books, but returns none of the 3.2 level books.

The code is a simple select query that ends up being:
SELECT * FROM MyTable WHERE ReadingLevel >= 3 AND ReadingLevel <= 3.x

View Replies !
Comparison Query?
I have two tables in my database that collect membership/user info. How do I write a query to compare the two and have the query spit out the users that are on one but not the other?

View Replies !
Previous Row Comparison
I have a table in this format:

Column A | Column B
1 | 2
1 | 3
1 | 4
2 | 5
.....
.....

What I want to do is something like this:

If in Column A there is a change in the number i.e. from the above table there were many 1s which transitioned into a 2. I want to record this change. I want to extract these two rows into another table. How can I make this possible?

View Replies !
Comparison Query
I have two tables, I have a company table and a client table. The fields in question are as follows

Company.companyid
Company.maincontactid
Contact.contactid

Due to bad design and bad data entry we have a bunch of companies with a contact number but no entry in the contact table. I want to run a query to dump a list of Company.companyid and Company.maincontactid where Company.maincontactid has no corrisponding Contact.contacid

View Replies !
Sql Comparison Tools
We've got a bunch of fairly long and complex sql statements that we need to compare between our dev and prd environments. The dev environment has been changed by a bunch of patches, while prd has been changed by an incompetent BA. Does anyone know of any tools that can help do this? Standard text/file comparison tools haven't been any help, so we're down to eyeballing them, which is both no fun and prone to error...

View Replies !
Dates Comparison??
I'm trying to find people from my db based on a given min_date and max_date using:

SELECT . . . WHERE birthdate BETWEEN '".$dd_min_age."' AND '".$dd_max_age."'
but if a range is specified there are no results returned.

If I choose though the same date for min and max then I get the corresponding results.

View Replies !

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