Solved

MySql: Date range problem

Posted on 2011-03-14
2
390 Views
Last Modified: 2012-05-11
The query below returns some website data between two dates.

It worked fine until I added the line:

AND `_website` LIKE '%" . $site . "%'

Now it only shows results for the lower date and not the date range.

How should I rewrite it?
SELECT
min( _tStamp ) _tStamp,
`_website` ,
`_sid` ,
`_tag` ,
`_ip` ,
`_host` ,
`_town` ,
`_region` ,
`_country` ,
count( DISTINCT _id ) _totalPageViews ,
max(_serverLoad) _maxServerLoad ,
min(_serverLoad) _minServerLoad ,
max(_pageLoadTime) _maxPageLoadTime ,
min(_pageLoadTime) _minPageLoadTime ,
sum( `_pageVisitTime` ) _totalVisitTime,
sum(`_pageScrollSeconds`) _totalScrolls,
sum( _pageClicks )_totalPageClicks ,
`_screenWidth` ,
`_screenHeight`,
`_userAgent` ,
`_referrer`
FROM visitor_logs_version_c
WHERE _host IS NOT NULL 
AND `_website` LIKE '%" . $site . "%'
AND (`_tStamp` BETWEEN  '" . $fromDate . " 00:00:00' AND  '" . $fromDate . " 23:59:59')
GROUP BY _sid
ORDER BY _tStamp DESC

Open in new window

0
Comment
Question by:AdrianSmithUK
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
>Now it only shows results for the lower date and not the date range.

AND (`_tStamp` BETWEEN  '" . $fromDate . " 00:00:00' AND  '" .$fromDate . " 23:59:59')

shall be:

AND (`_tStamp` BETWEEN  '" . $fromDate . " 00:00:00' AND  '" . $toDate . " 23:59:59')
0
 

Author Closing Comment

by:AdrianSmithUK
Comment Utility
What a Donkey!

Many thanks :@)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

763 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