Oracle compare number date between two dates - sql

I have a field with the data type of number which represents a date
eg: 20060421
I have two other fields in other table with the data type of Date.
I want to retrieve the rows from the first table that lies between those two Dates present in the other table.
How Can I compare the date in simple number format in a between clause of two Dates of data type Date.

I think the simplest solution for you here is to just cast the numeric date into a date type and then just use the built-in BETWEEN function.
-- sample cast
select to_date(to_char(20060801),'YYYYMMDD') from dual
so your solution should look something like this:
select *
from numericDatesTable t1, otherTable t2
where to_date(to_char(t1.date),'YYYYMMDD') between t2.date1 and t2.date2

Related

AWS Athena query to find Date column has String or not satisfying timestamp format

I was testing Sprak 3 upgrades in AWS Athena and need to check date columns whether timestamp format is proper or not,Can any one please give me query to check whether date columns has any Values other than Timestamp format
Assuming that you have a varchar column you can try using date_parse wrapped in try:
select *
from table
where try(date_parse(string_column, 'your_expected_format')) is null -- assuming no original nulls in column
Or via try_cast for "standard" format:
select *
from table
where try_cast(string_column as timestamp) -- assuming no original nulls in column

Why Date/Time statement in access returning no values?

Table has an End_Date column (Datatype: Date/time) with last date of every month
When I run the query I expect all records with End Date less than for example 31-Dec-2019
Select * from Table where End_Date < 31/12/2019
But it returns no result
When dealing with dates in Access, you need to ensure that they are wrapped in octothorpes ("#"):
SELECT * FROM Table WHERE End_Date<#31/12/2019#
Regards,

How to compare dates or filter data based on Date in sybase?

I want to fetch data for a particular date, datatype for this column is DateTime.
Tried below query:-
SELECT * from table_name where transaction_date=convert(DATETIME,'02/21/2017',101)
But above query is not working and returning no result, please could someone point out what I am doing wrong.
If you need compare dates with day precision you can use datediff function as below.
SELECT *
from table_name
where datediff(dd,transaction_date,convert(DATETIME,'02/21/2017',101))=0
More information about DateDiff

DB2 simple date comparison

I have two column with date type in table.
Now my objective is to extract all rows where this two column having different value.
Something as below:
Select * from tableA where dateColA != dateColB;
But I get SQL0181 Value in date, time, or timestamp string not valid

Query to fetch records from a table, for a particular date if the date column is in date data type

Query to fetch records from a table, for a particular date if the date column is in DATE data type.
Iam working in DB2.
if i give data format in 03/06/2011(mm/dd/YYYY)
ex:
Select * from table customer where date = "03/06/2011" is not working. date column is DATE data type.
Change double quotes to single quotes, maybe?
Select * from table customer where date = '03/06/2011'
Also, using ISO format to specify a date value might be more reliable:
Select * from table customer where date = '2011-03-06'
I think you need to convert your string date to an actual Date, like this:
Select * from table customer where date = DATE('03/06/2011');