how to resolve the problem that TDengine database has no function that converts the date format - tdengine

how to resolve the problem that TDengine database has no function that converts the date format?
I want to know the my data belong to which year, month, and day.
but not a specific timestamp

you can use TDengine database's "timetruncate" function to get the format you need like:
select timetruncate(ts,1d),value from tables.

Related

Why am I seeing values of '2432-82-75 50:08:01' in Oracle DATE column?

As part of my job duties, I'm responsible for extracting data from our vendor's Oracle 11g database, and loading it into our SQL Server 2016 database. I've been doing this successfully with SSIS and the Attunity Oracle connectors.
Today I was informed that there was a new column added to the existing Invoices table on the Oracle side. There was already a DATE column called Order Date, which contains valid date values with zero'd times, like 2017-12-25 00:00:00.
The new column is called Order Date Time and is also a DATE column. When I opened up the SSIS package and pulled up the Oracle source in my DFT, I previewed the data and found the values in Order Date Time to be 2432-82-75 50:08:01. I tried converting the column with CAST and all the TO_* functions, but the conversions either failed outright, or returned a string of zeros.
TO_CHAR("Order Date Time", 'YYYYMMDDHH24MISS')
yields 00000000000000
After a bit of Googling for "Oracle date value invalid", I'm now thinking that these DATE values are actually corrupted. Am I missing anything here? Is there some sort of special Oracle-specific technique for storing time values in a DATE column that I may not be aware of?
(And yes, it does bother me quite a bit that our vendor added another DATE column instead of just using the time portion of the existing Order Date column.)
Unfortunately, Oracle database engine allows inserting invalid date values, which leads to many problems especially when importing data to others database engines such as SQL Server.
To handle this issue, you have to implement the logic that fits your needs, as example:
You can exclude these records from you queries by filtering on acceptable date ranges: (WHERE date between ...)
You can Update records with invalid values by replacing with NULL
You can use a CASE statement in your query to replace values with NULL
I faced this issue one time while importing data to SQL Server from an Oracle data source, there was unacceptable date values, i decided to update all records where date are invalid and replace with NULL values before starting the import process.
There are many links related to this issue:
Detecting invalid values in the DB
How to identify invalid (corrupted) values stored in Oracle DATE columns
Corrupt date fields causing query failure in Oracle
Invalid Date in DATE Column SQLPlus VS SQLDeveloper
Ask Tom - date validation in oracle
Dealing with invalid dates
Error: Invalid date format
DB Connect; Oracle DB date field data is corrupt

Date format in Excel file to load to SQL Server

Our business would be providing us a .csv file. One of the columns in the file would be in date format. Now as we know there are many date formats in Excel. The problem is that we need to check whether the date provided is a correct date. It could be in any format like ddmmyyyy, yyyymmdd, dd-mon-yyyy etc basically any format that Excel supports.
We are planning to first load the data in a staging area and the date field would be defined as varchar so that it can accept any data.
Now either using SSIS or via T-SQL, I need to check whether the date provided is actually a date and if it is I need to load it into a different table in YYYYMMDD format.
How do I go about doing the above?
Considering you have your excel data already loaded into a SQL Server table as varchar (you can easily do this using SSIS), something like this would work:
SELECT
case when ISDATE(YOUR_DATE) = 1 then CONVERT(int,YOUR_DATE,112) else null end as MyDate
FROM
YOUR_TABLE
I don't have access to a SQL Server instance at the moment and can't test the code above, so you may need to adapt to your needs, but this is the general idea.
You can also do further research on ISDATE and CONVERT functions in SQL Server. You should be able to achieve what you need combining them together.

SQLPro for MSSQL date query off by one day

I'm running the following query on a table from SQLPro for MSSQL:
SELECT * FROM MyTable where Date = '2016-06-28'
The Date column contains fields formatted as datetimes for example: '2016-06-27 19:00:00:000'. When I run the query it returns results whose entries in the Date column are one day earlier than the date I queried for. So in the above example all results returned have date '2016-06-27'. There is data for the date I'm looking for since if I query for '2016-06-29' I get the data for the 28th.
Further, when I query from a cursor using pymssql I get the data for the right dates so it seems like the issue is with SQLPro and not the database itself. Anyone know what's going on/how to fix it?
Developer here. It is indeed a bug with SQLPro. I've sent a fix to #stableMatch which should resolve the issue.

SQL Server - Date is converted to integer

I am exporting data from Excel to SQL Server through an API. Everything is supposed to save as nvarchar but date is stored as int value (automatically). How can I keep, in SQL table, date value as it is i.e. like 01/01/1990 instead of 32874.
Might be a basic question, Googled and looked into SO but couldn't find what I am after yet. Help appreciated!
In SQL Server, you can convert to a date by using:
select dateadd(day, 32874, '1899-12-31')
There is probably also a way to fix this when importing the data, by treating it as an actual date or string.

MSSQL Datetime Conversion US Format

I have a problem with datetime conversions in MSSQL. We need to migrate ORACLE inserts into MSSQL acceptable inserts.
Therefore we need to change TO_DATE() calls to CONVERT(datetime..).
The date format that is given to us, is the following:
'12/31/2001 23:59:59'
We searched for the matching format on MSDN (http://msdn.microsoft.com/de-de/library/ms187928.aspx), but couldn't find any format matching this (as I understand) standard US format. Are we doing something wrong? Do we need to put the date and the time together in two separate converts?
An

Resources