Solved

Simple query using a timestamp field and a date range

Posted on 2011-03-10
6
508 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 78

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 78

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

734 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