Date field in where clause - if date in field is >= 67 - sql

I am trying to pull up records based on a datetime field. In the where clause I want the query to look at the date in the datetime field and if its greater than or equal to 67 days, I want the records to show up. How do I do this?
I have used the sysdate in the where clause before.

I got it working. Thank you to those who were going to help.
Answer: trunc(sysdate-s.affecteddate) > 67
I am using MS Access via pass through query.

Related

Filter DateTime in MS Acess 2010 Database

I have 5070 rows in a Table. But in that many entries are dump entries. I simply want to ignore them. In dump entries I have 1900-01-01 00:00:00 this data in many rows, I want to ignore all the rows which is having above data.
My query looks like this
Select * from Table where AttendanceDate > #1900-01-01 00:00:00#
I tried using CDate(1900-01-01 00:00:00), "#1900-01-01 00:00:00#", <> #1900-01-01 00:00:00# as well, but nothing helps.
I have gone throuh around 15-20 SO Questions and tried their marked answers but didn't work.
EDIT
I have data like this. I want to filter data that has InTime > 1900-01-01 00:00:00.
The table has only 650 valid entries from 5070 entries. I want to remove all the other extradump entries.
Any help would be appreciated!
Thank you
As suggested in the comments you have to use the date literals in the format #MM/dd/yyyy HH:mm:ss#.
So "SELECT * FROM tbl1 WHERE Datum > #1/1/1900 00:00:00#" should work in your case. Best practise is to use parameters as mentioned in the comments but the previous SQL statement should just work fine for you.
The data type of the field in question shoud be date/time.
PS: One could use the DateValue function to convert the text in date but this will cause trouble as one can never be sure if the conversion has been successful. IMHO it's best to have the correct data type from the very beginning
"SELECT * FROM tbl1 WHERE DateValue(Datum) > #1/1/1900 00:00:00#"

where-clause based on current and record date

I'm struggling to add a where-clause based on the difference of the current date and the date of the record entry. There are some other simplistic clauses as well, but I have no problem with those, so I'm making the demo data simple to highlight the issue I'm having.
Demo dataset:
Rec_no Rec_date
77 20170606
69 20170605
55 20170601
33 20170520
29 20170501
Date is recorded in format yyyymmdd and I'd like to build a where clause to only show records that are created X number of days ago from current date - lets say 10.
So, in this case, only records no 33 and 29 should be shown.
Unfortunately I'm not sure on what the actual DB engine is, but it should be something from IBM.
How could this be done?
As suggested in the comments updating the schema to store the date at the correct type is the best option before you start, however if this is not possible for whatever reason, you would first need to convert the stored date to the correct format at runtime.
I'll write an example in t-sql as that's what I know. Once you have worked out your dbms i can edit to the relevant functions/syntax
Select *
FROM Demodataset
WHERE Cast(Rec_Date as datetime) >= dateadd(day,-10,getdate())

How to select SQL Server data based on today's date and time?

I'm using SQL Server to COUNT some data which originates from a HTML table. I want to COUNT total rows in the database based on today's date. And then after the date hits tomorrow's date, to set the COUNT value back to zero and to restart the count back from the start.
Is there a query that can help me fetch data based on current date and time?
Something like this:
SELECT COUNT(data_id)
FROM table1
WHERE clock_time BETWEEN 000000 AND 235959
AND date_time IS TODAY's DATE (or something like that)
GROUP BY XXX
ORDER BY XXX
After the clock hits tomorrow's date, I want to reset the COUNT back to zero, and to start a new count back from 00:00:00.
I know there is NOW() query but as far as I know it only shows the date.
Someone told me I could use WHERE DATE(date)=CURDATE() but the SQL Server won't work with that.
Thank you...
You can use convert function like this
where convert(Date,date_time)= CONVERT(Date,GETDATE())
Need not to use time as you want today's data.
Try this one
SELECT COUNT(data_id) FROM table1
WHERE convert(date,date_time) = getdate()

How to update Oracle Timestamp value from the current to a timestamp from the past

I have an Oracle Table called EVENT_TABLE_T. It has a column called LAST_UPDATE_DT. One sample value from this column is: 01-JUL-13 11.20.22.37448900 AM. There are over 700 rows that have this same timestamp value.
I would like to update this value to 45 days before this date, using a SQL statement.
For example,01-JUL-13 11.20.22.37448900 AM, after my mental arithmetic, should become: 15-May-13 11.00.00...... (exactly 45 days).
If this is successful, I would like to apply an update on a different value in LAST_UPDATE_DT that reflects a value that goes back back 46 days.
What I hope to accomplish by asking this question is to be able to learn the basics of Oracle dates and timestamps and apply them to my batch processing work.
I would like to be able to run this update sql statement from Oracle SQL Developer and also from inside a Java PreparedStatement.
Thanks in advance for your help.
You can simply subtract a time interval from the timestamp.
UPDATE EVENT_TABLE_T
SET LAST_UPDATE_DT = last_update_dt - interval '45' day
WHERE LAST_UPDATE_DT = TO_TIMESTAMP('01-JUL-2013 11:20:22:37448900','DD-MON-YYYY HH24: MI:SS:FF')
Try something like:
UPDATE EVENT_TABLE_T
SET LAST_UPDATE_DT = TO_TIMESTAMP('15-MAY-2013 11:00:00:00','DD-MON-YYYY HH24:MI:SS:FF')
WHERE LAST_UPDATE_DT = TO_TIMESTAMP('01-JUL-2013 11:20:22:37448900','DD-MON-YYYY HH24: MI: SS:FF')
similar for the update you want for going back 46 days.
Check for syntactical error if any

Rally Excel Add-In Creation Date Query

I am trying to run a query from the Excel add in to capture the # of defects in a certain date range.
For example:
Query: Defects Sprint 93
Type: Defect
Order: Creation Date
Columns: Creation Date
Filter: ((Creation Date >= 09/06/2012) AND (Creation Date 09/20/2012))
Note: I copy and pasted the filter string from the rally website. When i ran this exact view in Rally i got the results I expected.
Any help would be greatly appreciated. Thanks!!!
You'll need to use ISO format for the dates and remove the space from the field name:
((CreationDate >= 2012-09-06) AND (CreationDate <= 2012-09-20))
I am agree with Kyle answer but little modification in my query it worked.
like ((CreationDate >= 2012-09-06) AND (CreationDate < 2012-09-21))
Note : in second CreationDate i increased the date by 1 from 20 to 21 ,it would satisfy the condition perfectly.