Azure Data Factory copy activity failed with Exception ERROR [22007] Timestamp is not recognized? - snowflake-cloud-data-platform

I am using Azure Data Factory to copy data from CSV to Snowflake, the copy executes fine but it has an error when it comes to copy Date from the CSV which has this value (14/01/2000), if the Date is (12/10/2000) or less, it works very well.
Here is the error message:
ErrorCode=UserErrorOdbcOperationFailed,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=ERROR [22007] Timestamp ‘14/01/2000’ is not recognized
I tried to adjust the format of the date in the copy activity to be dd/MM/yyyy or change the Culture to en-UK as the below image but it has the same issue.
I tried to use all the possible types of date in Snowflake as below but I still have the same issue:
DATE
DATETIME
TIMESTAMP
TIMESTAMP_LTZ

Snowflake doesn't supports format as DD/MM/YYYY and even it supports MM/DD/YYYY it can lead to incorrect dates (05/02/2013 could be interpreted as May 2, 2013 instead of February 5, 2013).
So this:
select '14/01/2000'::timestamp;
produces:
Timestamp '14/01/2000' is not recognized
while this:
select '01/14/2000'::timestamp;
produces:
2000-01-14 00:00:00.000
Same for:
select '14/01/2000'::date;
select '01/14/2000'::date;
The guidelines for how to use date/timestamp formats are described here.
In your case one way to get that value as a date is to use the to_date function, like this:
select to_date('14/01/2000', 'DD/MM/YYYY');
gives me:
2000-01-14

Related

Get date in date format from SQL Server

I have a table in SQL Server with a date column set to default date, however, when I fetch the data from the server using VBA I get the date column in string format. Is there any way I get the date as in date format?
Can you you advise how you are bringing in the data? EG from inbuilt connectors or via a recordset via VBA objects?
A quick hack which I wouldn't advise without really testing would be this :
Select DateDiff(DD, '1899-12-30', date_column) AS [column] from TABLE_x
What is this doing?
In Excel dates start 01-01-1900. When you change a date to 'General' you find it's actually a number with a format. The above date difference will give you the excel number version of the Date.
EG to get today 29/11/2019 which will be 43798 when cell format is 'General'.
Select DateDiff(DD, '1899-12-30', '2019-11-29') AS [column]
More info here
Non MS site explaining the situation
MS Office Info touching on the subject
Please note this basing your question on a SQL formatted date.

Get date from int (YYYYMMDD)

By doing a mistake a few months ago I got myself in a situation, where I have to find a workaround for the following problem:
I am saving dates as integer in a common format inside my SQL Server database (YYYYMMDD). I want to have my select statement giving me the integer in a format, that looks like a date (or even is in a true date type) to the user, so I can use the received datatable directly as datasource for my DataGridView.
I do not want to use clientside formatting
Let's call the table myTable and the integer/date column myIntDate
myIntDate can be NULL
sample myIntDate-value : 20160803 for the 3rd of August 2016
Select cast(cast(20160729 as varchar(10)) as date)
Returns
2016-07-29
Or
Select cast(left(20160729,8) as date)

Day/Month/Year date changed to Month/Day/Year in SQL

I have an old Classic ASP application that was worked perfectly, recently it was moved to window server 2012 server with IIS 8.5, the problem is that I have a form to add record with Day/Month/Year format, when the date entered as 23/06/2015 in SQL will be added correctly as 23/06/2015 but when date entered as 01/06/2015 : 1st june 2015 in SQL will be added as 06/01/2015 Month/Day/Year which will be incorrect
I checked the location and date format for the server and it was dd/mm/yyyy, and the database didn't changed since the old server SQL 2008.
I searched the net and found the i need to change the IIS culture under GLOBALIZATION, but I don't know what to choose even if I chose my country still I am facing the same issue.
If you don't want to get into changing globalization and localization settings, the simple answer is to use the universal date input YYYYMMDD when inserting dates as strings.
Update
To expland on your comment: when changing the format of the date string in an insert/update query it does not change the format within the sql table itself.
e.g.
UPDATE [table]
SET [column] = '20150716 10:22'
WHERE Id = 7489
When viewed displays the same as the other records in the table:
Try this:-
https://www.webwiz.co.uk/kb/asp-tutorials/date-time-settings.htm
Add an entry into global.asa as below...
'When a session starts on the server the following code will be run
Sub Session_OnStart
'Set the server locale
Session.LCID = 2057
End Sub
Somethimes when nothing fix this problem (or a global solution could damage old scripts), A workaround that you could use is the convert function, to change the format in your stored procedure.
For Example:
select getdate() --prints 2018-10-05 12:24:43.597
select Convert(char(10),getdate(),103) --To force the date to be dd/mm/yyyy
And not leting the asp page to format the date, just print raw.

Search By Date in SQL Server 2012

We just upgraded to SQL Server 2012 from 2005. While I'm a novice, something this simple couldn't be this difficult. I used to be able to pull data from a table based on the date vs date and time. As it now stands I have:
Select * from receipts_table where receipt_cancel_date = '2013-09-20'
before we upgraded this would work fine. How can I run this and actually get the desired results as I know there's receipts with a cancel date of 2013-09-20.
Thanx
If you are passing string for a date parameter, best format is ISO (yyyymmdd) format. Otherwise even though your string work in some servers it might not work in another depending on the culture of the server. ISO format is culture independent.
Also remove the time part from receipt_cancel_date column by converting it to a DATE (if DATETIME) for comparison purpose.
Try this:
Select * from receipts_table
where convert(date, receipt_cancel_date) = convert(date,'20130920')
Or use 120 style with your format:
Select * from receipts_table
where convert(date, receipt_cancel_date) = convert(date,'2013-09-20',120)

SQL Date Type Conversion Error

I get the date like this
DateTimePicker1.Value.Date.ToShortDateString()
and try to insert to my database.
The error is :
Conversion failed when converting date and/or time from character string.
It was working yesterday. Today I delete all values in my table and is not working now
It looks like your app server and db server have different regional date setting. Also, DateTimePicker1.Value.Date yields a DateTime and you should use that to add it into the db without having to go through the regional conversion mess.
Get your date using:
CDate(DateTimePicker1.Value.Date.ToShortDateString())

Resources