Insert date into date9 - date

Within my PROC SQL snipped I am trying to compare a column of datatype date9. to the date 31.12.2015'. I tried:
test_date = '31DEC2015'
This returns me the following error:
ERROR: Expression using equals (=) has components that are of different data types.
What would be the correct syntax?

Add "d" to the end of the quoted date value:
test_date = '31DEC2015'd;

Related

Inserting CURRENTDATE for DATE column fails in PostgreSQL

i am trying to insert CURRENTDATE as the value for a field that has the type defined as "Timestamp without Timezone".
INSERT INTO monthly_forecasts VALUES
('1','DIV1','Mon','Tue','Wed','Thu','Fri','','','','','-3',CURRENTDATE, CURRENTDATE)
But I get this error when I do that:
ERROR: column "currentdate" does not exist
LINE 2: ...'Mon','Tue','Wed','Thu','Fri','','','','','-3',CURRENTDAT...
^
How do I insert current date as the value for this field? Please help!
As documented in the manual the function is named current_date, not currentdate.
But as your column is defined as timestamp, you should use current_timestamp to include the time of the day (a DATE doesn't have a time)

Convert packed DB2 iseries value to YYYY-MM-DD

I'm trying to select records from a DB2 Iseries system where the date field is greater than the first of this year.
However, the date fields I'm selecting from are actually PACKED fields, not true dates.
I'm trying to convert them to YYYY-MM-DD format and get everything greater than '2018-01-01' but no matter what I try it says it's invalid.
Currently trying this:
SELECT *
FROM table1
WHERE val = 145
AND to_date(char(dateShp), 'YYYY-MM-DD') >= '2018-01-01';
it says expression not valid using format string specified.
Any ideas?
char(dateshp) is going to return a string like '20180319'
So your format string should not include the dashes.. 'YYYYMMDD'
example:
select to_date(char(20180101), 'YYYYMMDD')
from sysibm.sysdummy1;
So your code should be
SELECT *
FROM table1
WHERE val = 145
AND to_date(char(dateShp), 'YYYYMMDD') >= '2018-01-01';
Charles gave you a solution that converts the Packed date to a date field, and if you are comparing to another date field, this is a good solution. But if you are comparing to a constant value or another numeric field, you could just use something like this:
select *
from table1
where val = 145
and dateShp >= 20180101;

Converting date format in denodo database

I'm trying to convert value for DIM_DT_ID to MMddYY. I'm successful in doinf that. However, query fails because ultimately I'm comparing a character value to date here. Is there a way by which I can get value for DIM_DT_ID in MMddyy format and its data type still remains DATE ?
Here DIM_DT_ID
SELECT DIM_DT_ID
DIM_DT_ID >= FORMATDATE('MMddyy',ADDDAY(TO_date('yyyy-MM-dd','2016-12-21'), -25)); from abc;
Regards,
Ajay
In Denodo, to convert a string to a date field, use "to_date()" (which returns a date).
Then, don't convert back to a string, leave that field as a date (so don't use "Formatdate()", which returns a string).
So:
SELECT *
FROM MyTable
WHERE now() >= to_date('yyyy-MM-dd',myStringFieldThatLooksLikeADate)
In my example, "now()" is a date, and so is the output of the to_date function... so you can do a comparison.
If you try to convert the date back to a string using formatdate, it won't work:
#This doesn't work:
SELECT *
FROM MyTable
WHERE now() >= formatdate('MMddyy',to_date('yyyy-MM-dd',myStringFieldThatLooksLikeADate))
It doesn't work because we are comparing a date ("now()") to a string.

DB2 For i: Convert Char YYMMDD to Date

I have a CHAR_Date column containing date values in the format 'YYMMDD'.
I would like to do date arithmetic so I need to convert it into a Date data type. The problem is that the Char_Date also contains Blanks.
How do I cast the CHAR_Date to a DATE_Date column, with valid values?
SELECT
case when CHAR_Date = '' then TIMESTAMP('0001-01-01')
else TIMESTAMP_FORMAT(CHAR_Date, 'YYMMDD')
end
as DATE_Date
FROM TABLE_Data
You can use the function TIMESTAMP_FORMAT
TIMESTAMP_FORMAT('990205' , 'YYMMDD')
And if you want a date:
DATE(TIMESTAMP_FORMAT('990205' , 'YYMMDD'))

How to convert characters to date in SAS proc sql

I have a column of data named yearmonth stored as characters data. I want to convert this column into SAS date in another column with format dd/mm/yyyy.
for example lets say one of the data is 201201. I want to convert it into 15/01/2012. The problem is I can only use the proc sql and unable to changed the data. Anybody can help me with this problem?
Edit:
This is the one I have done :
INPUT("01/" || substr(t1.Yearmonth, 5,2) ||"/"|| substr(t1.Yearmonth, 1, 4),ddmmyy10.)
Your dataset with character YYYYMM dates:
data input ;
input date $ ;
cards ;
201201
;run ;
You can create a new variable as below:
proc sql ;
create table output as
select date, input(date, yymmn6.)+14 as newdate
from input
;quit ;
You can try the below;
data test;
mydate='20120115';
date_new = input(mydate, ddmmyy10.);
format date_new date10.;
run;