Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Selecting Records for Today only?

Guest
Dec 04, 2009 Dec 04, 2009

I feel this should be an easy one, but everything I try is throwing back zero results.

Basically, I have an existing query that uses an outer join to bring 2 tables together (it's for some very basic site tracking).

Without the 'WHERE' clause, it performs exactly as I'd hoped.  However, I need to be able to narrow down the results to the current day only (and perhaps other date ranges in the near future).

The final output I'm looking for is a list of sites, and the unique visitors for each.  Again, this works fine when I run it without narrowing down to today only.  The 'eventdt' field on the MySQL server is a datetime type.

<cfquery name="getsites" datasource="#datasource#">
SELECT s.id, s.sitename, count(DISTINCT t.uuid) as t_cnt, t.eventdt, t.sitename AS tracksite
FROM sites s
LEFT JOIN tracking t
ON s.sitename=t.sitename
WHERE t.eventdt = #CreateODBCDate(now())#
GROUP BY s.sitename
ORDER BY s.sitename ASC
</cfquery>

Thanks in advance for any pointers 🙂

TOPICS
Database access
385
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Dec 04, 2009 Dec 04, 2009

today = createdate(year(now()), month(now(), day(now()));

tomorrow = dateadd("d", 1, today);

in your query

where eventdt >= today

and eventdt < tomorrow.

With proper syntax of course.

Translate
LEGEND ,
Dec 04, 2009 Dec 04, 2009

today = createdate(year(now()), month(now(), day(now()));

tomorrow = dateadd("d", 1, today);

in your query

where eventdt >= today

and eventdt < tomorrow.

With proper syntax of course.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 04, 2009 Dec 04, 2009
LATEST

Excellent, thanks Dan 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources