Teradata Date calculation format issue - date

I have this date set uploaded from SAS to TD and the date format is like MEDI_START_DT format,'MM/DD/YYYY'
And now I want to make a calculation baesed on this column
MEDI_START_DT + PDAYSSUP -1 = MEDI_END_DT_PRE
but MEDI_END_DT_PRE's format is not a date and I tried cast(MEDI_END_DT_PRE's as date) and it says invalid date.
Do you guys have any idea on how to get a date format result after the calculation? Thanks!
enter image description here

If you loaded the data from SAS and it was formatted as a DATE in SAS then it should work. You should check if your PDAYSSUP variable got defined as FLOAT in Teradata. Try casting that variable:
select MEDI_START_DT + cast(PDAYSSUP as integer) -1 as MEDI_END_DT_PRE
from ...

Related

DataStage Parsing Input String to Date Format

I have a string input format of i.e
'Thu, 30 Nov, 2017'
I need to transform this into a more Oracle database friendly Date type format of something like '11-30-2017' or '11/30/2017'. I started in the path of
Convert(' ','-',Convert(',','',DSLink.InputDate[5]))
which should return a string of: 30-Nov-2017
However I'm stuck on dynamically parsing the 'Nov' month part. Any clever ideas?
also I don't think this will work:
StringToDate(Convert(' ','-',Convert(',','',DSLink.InputDate[5])),"%dd-‌​%mm-%yyyy")
as the function is looking for a numeric type on the month field?

wrong date when i change int time with FROM_UNIXTIME

I have a old database that i want to transfer, but i have some trouble with my column dateP(int). I got a wrong datetime.
In my old script, I enter the date-time like this:
$date_created = time();
$data_insert = "INSERT TO table $date_created, $title";
Now I have the column datePub (int) that I convert to time stamp format,
For resolve this problem i make this.
UPDATE `table ` SET `date_created` = FROM_UNIXTIME(`datePub `)
But I got a wrong date when I make this date('M d, Y', $PuDate);
I put the right specifier in date_format and its good now.

create categorical variable in sas based upon date

I want to create a categorical variable based upon date and input the following code.
data temppricedata;
set SASHELP.PRICEDATA;
date_group='';
IF (date>='MAR2002'd) THEN
date_group='new';
IF (date<'MAR2002'd) THEN
date_group='old';
run;
However I got error like
ERROR: Invalid date/time/datetime constant 'MAR2002'd.
ERROR 77-185: Invalid number conversion on 'MAR2002'd.
I am sure the format follows sas date format which is MONYY.
I do not know how to correct this.
As #Jeff mentioned, the correct way for specifying SAS date constants is DDMONYY or DDMONYYYY.
data temppricedata;
set SASHELP.PRICEDATA;
length date_group $3.;
IF date >= '01MAR2002'd THEN date_group='new';
ELSE IF date < '01MAR2002'd THEN date_group='old';
run;

Date display Appery.io

I use a date picker that saves the date in a yyyy-mm-dd format in a database. It then automatically adds time that always appears as 00:00:00. So for example it displays the date like this : 2014-12-14 00:00:00. I want it to display just the date in a mm-dd-yyyy format.
I use the code below but something seems to be wrong with it because it simply doesn't change the way it is displayed. I want to split up each of the values, then display only the date in a different format.
var parts = value.split("/");
return parts[1] + "-" +parts[2] + "-" +parts[0];
What can I do to make it work? Javascript please.
Thanks in advance.
It's a wide variety of solutions. Depends on you server-side settings too, but I will assume, that you use common for most websites MySQL DB and PHP.
You can change you column type to DATE. As said in docs:
The DATE type is used for values with a date part but no time part.
MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. The
supported range is '1000-01-01' to '9999-12-31'.
You can change your column type to VARCHAR and store a date in any format you like when INSERT it
You can convert it to proper format using MySQL built-in DATE_FORMAT()
SELECT DATE_FORMAT('2014-12-14 00:00:00', '%c-%e-%Y');
will give you 12-14-2014. Here is sqlfiddle,
just change first param to your column name in query
On server you can use PHP's date() function like this
$yourdate = '2014-12-14 00:00:00';
echo date("m-d-Y", strtotime($yourdate));
Closer to your question, how to do it in JS? It also has special object for this: Date(). Put your date in constructor, then use methods:
var yourdate = new Date('2014-12-14 00:00:00');
alert(yourdate.getMonth() + "-" + yourdate.getDate() + "-" + yourdate.getFullYear());
JSFiddle < - here
So, as far as almost every platform understands this datetime format - you can use any tool for converting it

Why does ExtJS subtract a day when formatting a date?

Using ExtJS 4.0.2, I can type the following into the console:
Ext.util.Format.date('2012-01-13', "m-d-Y");
I get 01-12-2012
Why?
I can correct it with:
Ext.util.Format.date('2012-01-13 00:00:00', "m-d-Y");
Ext.util.Format.date in Ext 4.0.2 uses a Date object or a String (your case). This string is parsed using the native Date.parse() using the UTC time zone.
Try to explicitly parse it using Ext.Date.parse:
var dt = Ext.Date.parse("2012-01-13", "Y-m-d");
Ext.util.Format.date(dt, "m-d-Y");
This problem exists in Ext3, but the solution is slightly different:
var dt = '2012-01-31'; //date string
dt = Date.parseDate(dt, "Y-m-d");
Ext.util.Format.date(dt, 'm/d/Y'); //returns 01/31/2012
If you're unable to use Gregor's answer (e.g. filling a grid), note that changing the input to a non ISO 8601 date format will avoid the UTC parsing as well. For example
Ext.util.Format.date('01/13/2012', "Y-m-d");
will give 2012-01-13