Solved

Simple query using a timestamp field and a date range

Posted on 2011-03-10
6
499 Views
Last Modified: 2012-05-11
New to mySQL.  This is on a Linux box running MySQL 5.1.52

How do I do a simple query to retrieve e a date range from a timestamp field?.

The field is named  time  .  I know, but I didn't name it. This is what I need to do iinteractively.

Select * from journal
WHERE time > 2009/12/31 AND
time < 2010/12/31

I also need to do the same in a form with two php form fields, startdate and endate, formatted as yyyy-mm-dd

Select * from diaries
WHERE time >startdate AND
time < enddate

Help please.
0
Comment
Question by:Waterstone
  • 3
  • 2
6 Comments
 
LVL 33

Expert Comment

by:jppinto
ID: 35097047
Select * from journal
WHERE time > #2009/12/31# AND
time < #2010/12/31#

0
 

Author Comment

by:Waterstone
ID: 35097157
Thanks, but it does not work.
Does not like the # signs. Turns the line into a comment.
0
 

Author Comment

by:Waterstone
ID: 35097178
Sorry,w as not specific.  I'm trying to run the query in mySQL, not a php page.  That must be the php code.

I'll try that in pfp after I verify that the data is there using an interactive query using Navicat or MySQL Workbench.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 76

Accepted Solution

by:
arnold earned 500 total points
ID: 35097302
Is the time column uses  timestamp format (int(10)) OR is it in date format?
could you post the show create table journal

the query tool in workbench and run
select * from journal where time >'2009/12/31' and time <= 'the end_dateof_interest'
0
 

Author Comment

by:Waterstone
ID: 35097539
Thanks, that worked. I was playing with date_format parameters and looking for a more complex issue. Field is named time, type is timestamp.
0
 
LVL 76

Expert Comment

by:arnold
ID: 35097796
For future use, I'd suggest that you use unix_timestamp (int (12)) as the definition of the column which represents the number of seconds since january 1st 1970 GMT
IT simplifies queries such that you do not need to use date_add or similar functions to manipulate the date.
i.e. adding or subtracting 3600 from the column, will result in an hour shift eiher way.etc.
When displaying the unix_timestamp can then be converted for date display and provides for better customization where the Timezone of the client needs to be taken into account. i.e. one is in the EST, GMT, Australian etc. and the interface can simply grab the timestamp and during the display convert it into the date with the right timezone.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi (http://code.openark.org/blog/mysql/on-restoring-a-single-table-from-mysqldump) had suggested a “sed” way, I actually shell …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now