Need help in teradata - teradata

In one of the tables I've a time column where the data is something like this :
01:21:00.000000
for all the records.
I want to retrieve the data which looks like below.
01:21:00 in teradata.
Please advise. I'm new to teradata and don't know how to achieve this

I don't know a reasonable way to go to less precision in time (or timetamps) in Teradata. Assuming your column is time(6), you can't just cast that to time(0). You get a DateTime field overflow error.
I do it by casting it to a character field and then back to time(0):
select *
from
<your table>
where
cast(cast <your column> as varchar(8)) as time(0) = '01:21:00'

If your column is timestamp, then we can use Timestamp(0) is YYYY-MM-DDbHH:MI:SS and Timestamp(6) is YYYY-MM-DDbHH:MI:SS.ssssss (milliseconds extra).
If your column is just time, then we can use 'CAST'.
select cast( as time(0)) from ;

Related

Snowflake GMT String to Date Conversion

We receive a string '2019-11-30T18:00:00GMT-06:00' in the JSON file and this need to be converted to timestamp to load into the timestamp column in the snowflake. I tried multiple options convert_timezone,to_timestamp etc, however in vain, Can you please let me know how i represent this string (2019-11-30T18:00:00GMT-06:00) in data format for comversion.
Thanks !
Leveraging a more Snowflake way to do this, you'd want to run something like this:
SELECT TO_TIMESTAMP('2019-11-30T18:00:00GMT-06:00','YYYY-MM-DDTHH:MI:SSGMT-TZH:TZM');
The output of this will be the date/time of your account default along with the timezone offset that goes along with that.
Please try the below mentioned approach
if your table is create as below
CREATE TABLE TIMESTAMP_TEST(DATE TIMESTAMP);
Insert the value as
INSERT INTO TIMESTAMP_TEST SELECT REPLACE(REPLACE('2019-11-30T18:00:00GMT-06:00','GMT'),'T',' ') FROM DUAL
Thanks

Error during compare date format in sqlite query

I was writing an application on c#, which is save DateTime to the Text field in the database.
Format of date is:
'1/15/2020 14:48:44', '2/11/2020 12:53:59' and etc
Now I want to get records with SQL query by the last few days.
I understand that I need convert text to date, and compare. But SQL query return 0 results. My query is:
select * from LogRootProcessing where strftime(dateparsing) < strftime('%MM/%DD/%YYYY %HH:%MM:%SS','2/11/2020 12:53:59')
Could you please advise how to fix the query?
Thanks in advance.

Convert integer column to date column using sqlite query

I am using SQLite.
In my database, I have a integer column value like 20050819. I would like to convert this as date column as like 2005-08-19.
I can achieve my requirement when using the function CONVERT(columnName, DATETIME) in MySQL server. But I need the same result in SQLite.
Is this possible in SQLite query?
You basically have to break apart the date:
select printf('%4d-%02.2d-%02.2d',
columnname/10000, columnname%10000/100, columnname%100)
from tablename;
P.S.
If you have the choice, you will be far better off storing the date in ISO standard format ('YYYY-MM-DD') in the database in the first place.

DB2 Stored procedure - Add hours as input to a timestamp

I want to create a stored procedure that has a IN_NROFHOURS as input.
Then I want to create a cursor that fetches all rows with the following condition:
select * from listtable where startdatetime + in_nrofhours > current timestamp
My questions are:
What is the best datatype for IN_NROFHOURS;
Given the datatype you suggest, how should the "where" condition be stated?
Thanks for your help, I appreciate that.

How to format date and time values for SQLite?

Can't believe I have to ask this here. Even googling didn't help.
I want to do this:
insert into atable (adatefield,atimefield,adatetimefield) values (A,B,C);
adatefield is defined as DATE
atimefield is defined as TIME
adatetimefield is defined as DATETIME
What do I put for A, B and C?
It's nice that it's free but the documentation for SQLite is awful.
A date, time and datetime field will actually all store datetime, it just depends on what you insert into it, and they will all work with date strings.
You can
insert into atable values("2010-11-16","14:12:22","2010-11-16 14:12:22");
or you can actually just insert "2010-11-16 14:12:22" into all the fields and then select them back with:
select date(adatefield), time(atimefield), datetime(adatetimefield) from atable;
If however you want to make sure that the fields only contain exactly a date,time or datetime and you're inserting from variables, then you can
insert into atable values(date(thedate),time(thedate),datetime(thedate));
Sqlites typelessness makes some things really easy, but can confuse or complicate some other things.

Resources