473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

SQL to automatically select only current date's rows

mbolan77
Hello...

I have a table with a number of fields along with a time stamp column... I am wondering how I can query for only rows inserted on the current date other than manually entering the date parameter... An example below:

Let's say I had a table like this:

OFF_ID OFFER RESULT ENTRY_TS
2719 MAGAZINE NOT INTERESTED 2006-09-27 16:11:06.678
2720 CAR ACCEPT 2006-09-27 16:15:02.231
2721 VACATION ACCEPT 2006-09-28 08:32:16.547
2722 T-SHIRT NOT INTERESTED 2006-09-28 08:41:22.812

I would use the following to get a count of just rows from today:

SELECT COUNT (*)
FROM INFO_TABLE
WHERE INFO_TABLE.ENTRY_TS > '2006-09-28';

However, I would like to instead have a query where it automatically pulls rows based on the current date without having to manually enter the date...

By the way, I am using MySQL against an MS SQL Server Database...

Thanks in advance for any assistance.
Sep 28 '06 #1
4 13948
ronverdonk
4,258 Expert 4TB
Use CURRENT_DATE. This will do that:
Expand|Select|Wrap|Line Numbers
  1. SELECT COUNT (*)
  2. FROM INFO_TABLE
  3. WHERE INFO_TABLE.ENTRY_TS > CURRENT_DATE;
  4.  
Ronald :cool:
Sep 29 '06 #2
Thanks for your response, I appreciate it.

Apparently I'm a moron on 2 counts.. :-)
1. I'm actually using WinSQL to query the database, not MySQL as I incorrectly noted in my previous post (not sure if that makes a diff)
2. I tried your suggestion and still can't get it to work (perhaps cuz of #1 above???). I get this message:

Error: Incorrect syntax near the keyword 'CURRENT_DATE'. (State:37000, Native Code: 9C)

Any suggestions?

Thanks again!
Oct 2 '06 #3
ronverdonk
4,258 Expert 4TB
You'll have to look in your WINSQL manual then to see if a similar function exists. Good luck.

Ronald :cool:
Oct 2 '06 #4
mbolan77 Why don't you try using the function getdate() it will give you the actual system date.
Sep 1 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Rowland Hills | last post by:
I have a table which is returning inconsistent results when I query it! In query analyzer: If I do "SELECT * FROM TABLE_NAME" I get no rows returned. If I do "SELECT COL1, COL2 FROM...
3
by: Fred | last post by:
I am trying to get al the rows from table1 where datetime is between 9:00AM yesterday and 9:00AM today if the time now is less than 9:00AM. Otherwise it should return all where datetime>9:00 AM...
5
by: QBCM | last post by:
I am trying to create a report by selecting three date fields from one table with records between a start date and end date. I have tried to adapt one of Allen Browne's scripts as follows but it...
1
by: Ray Valenti | last post by:
Saving the current date to an Access Database returns an error. this.dsMain1.Tables.Rows= DateTime.Today.ToString(); this.oleDbDataAdapter1.Update(this.dsMain1,"Links"); Tried several formats,...
5
by: robecflo | last post by:
Hi Forum, i have a problem, hope somebody can give me ideas. I'm developing with windows forms and vb.net, and oracle as a database. At this moment i have a table called amortizaciones, this table...
2
by: gimme_this_gimme_that | last post by:
Ideally I'd like an equivalent of : current date - 5 days which works for minutes instead of days... --- But, assuming I have a table with a timestamp column named modified_date , how...
2
by: GrandVizier | last post by:
Hej With SQL Server 2005 I'm trying to run a query that gets a passenger list from multiple tables. The ultimate goal is to output this information in a report. There are 3 tables (each of these...
13
by: Directory | last post by:
It may be simple for many of you. But I am stuggling with this. I have a simple table like this. I want to select the records with one record per each name which has recent date. the result should...
2
by: emceemic | last post by:
Is there a way to show multiple rows per row if required? For example, say the table I currently have show the following data: Impact to Business, Business Owner Name, ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.