Reputation: 59
I want to pull data from a database based on today's date. I do not want to have to type in a date every time I run this. I want this to be something I can run every day and base it on the current date.
I do not want to interfere with the data stored. I am only trying to retrieve data based on today's date. I think I should not have to go through making a variable for the date and should just be able to use curdate() or something?
Pseudo code:
declare variable as X (or whatever to represent the date)
then tell getdate() to populate X (determine what X is)
then
select EntryDate, Name
from Table
where EntryDate = X or where EntryDate is CurDate() ????
so that it will print out something like this:
29Aug14 Suzie Que
29Aug14 Frank Man
29Aug14 Zebo Bebo
29Aug14 Tim Fields
29Aug14 Martha White
Upvotes: 0
Views: 104
Reputation: 59
I was using sysdate all wrong. I ended up using something like this:
select st.pers_ID, sh.request_date, sysdate
from pers_id st
join .....
where
sh.REQUEST_DATE between sysdate-1 and sysdate
This enabled me to always pull the last 24 hours. Since this will be run at the same time every day (automatically and before business hours), it should be fine. Thanks!
It printed something like this:
ID request_date sysdate
81432 10-sep-14 11-sep-14
45796 11-sep-14 11-sep-14
Upvotes: 0
Reputation: 763
Assuming EntryDate
is a date field you can do something like this
select EntryDate, Name
from Table
where EntryDate = SYSDATE
I believe SYSDATE
will have time too, so if you are comparing dates only do some formatting to get it to match
Upvotes: 1