I have a table field in below format in snowflake. While trying to_date(), to_timestamp() function, its erring out with error message as - Timestamp '8/05/2018 9:03:53 PM' is not recognized.
Format - '8/05/2018 9:03:53 PM'
Specify the format in the TO_TIMESTAMP as follows:
to_timestamp('8/05/2018 9:03:53 PM','MM/DD/YYYY HH12:MI:SS AM') -- assumes MM/DD/YYYY
or
to_timestamp('8/05/2018 9:03:53 PM','DD/MM/YYYY HH12:MI:SS AM') -- assumes DD/MM/YYYY
The format you are using is ambiguous, is it 8th May or August 5th?
Due to the above we don't support that date format.
For more information have a look here
Related
I have dates in integer format in a column. The length is 11.
Example values
current format integer (11) --> date format required
yyyymmdd --> dd/mm/yyyy
20121203 --> 03/12/2012
20090403 --> 03/04/2009
Can someone suggest a solution keeping in mind that the change need to reflect across the entire column in the table?
Use STR_TO_DATE :
select STR_TO_DATE(col1, "%Y%m%d") as my_date
from test_tbl;
Result:
my_date
2012-12-03
2009-04-03
Demo
Or DATE_FORMAT as previous answer:
select DATE_FORMAT(col1, "%d/%m/%Y") as my_date
from test_tbl;
Result:
my_date
03/12/2012
03/04/2009
Demo
Maybe using both:
select DATE_FORMAT(STR_TO_DATE(col1, "%Y%m%d"),'%d/%m/%Y') as my_date
from test_tbl;
my_date
03/12/2012
03/04/2009
Demo
The easiest way is based on Teradata's storage of dates:
Cast(intdate - 19000000 AS DATE)
Of course this only works if there are no bad dates, as your source seems to be MySQL there might be 20220200, etc.
For Teradata SQL Assistant, you can use TO_CHAR and then CAST it to a DATE format like this:
SEL CAST(TO_CHAR(20211015) AS DATE FORMAT 'YYYYMMDD')
Result: 10/15/2021 (mm/dd/yyyy)
Docummentation: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-format
DATE_FORMAT("20121203", "%d/%m/%Y")
Can't format the below date using moment.js, the below statement returns Invalid Date
moment('20171206T062406927Z').format('D-MMM-YYYY');
Please help me on this.
You need to tell moment which format your date string is in:
moment('20171206T062406927Z', 'YYYYMMDD[T]HHmmssSSSZ', true).format('D-MMM-YYYY');
Edit: updated as per #VincenzoC comment to ensure the timestamp is parsed in UTC
Also fix: use HH for 24-hour format (not hh), and pass a third true parameter to ensure the timestamp is parsed in strict mode.
I am having a timestamp in the format YYYY-MM-DD HH:MI:SS and I want to convert it in the format MM/DD/YYYY HH24:MI:SS.
What is the easiest way to achieve it?
The format of a timestamp is only applied when it's casted from/to a string
-- using Teradata's format
Cast(Cast(ts AS Format 'MM/DD/YYYYBHH:MI:SS') AS VARCHAR(19))
-- shorter using Oracle's To_Char
To_Char(ts, 'MM/DD/YYYY HH24:MI:SS')
I get exception when try to use CONVERT_TZ in RoR project:
SQLite3::SQLException: no such function: CONVERT_TZ
Is there some function in sqlite for convert timezone in a query?
To convert from UTC+0 to UTC+3:
SELECT datetime(columnName, '+3 hour') || '+03:00' AS myDate FROM tableName;
Explanation:
datetime(columnName, '+3 hour')
Above does the translation of hours, it simply tells SQLite to add 3 hours to the initial date. This would not be enough, because it only modifies date, without really telling that the timezone has changed, so we can do it manually, by appending '+03:00' to the final date string.
It makes the following conversion from 2015-03-05 15:03:43 to 2015-03-05 18:03:43+03:00
That means that the date format will change from YYYY-MM-DD HH:MM:SS to YYYY-MM-DD HH:MM:SS[+/-]HH:MM, which is a correct datetime format for SQLite, according to its documentation.
Read SQLite's documentation about date functions for any details, or just ask in comments and I can try to help even further. I don't want to paste the entire documentation page here.
I want to show a date in DD-MM-YYYY format in a datagrid. By default, SQLite stores the data in date-time format. So how can I convert date-time format to date format in flex by using SQLite?
You can use strftime, from Date And Time Functions.
Example:
SELECT strftime('%d-%m-%Y', 'now')
output:
10-06-2010
Look up Java until Date. It has methods to convert and is supported in SQLite. However it is mostly deprecated and replaced with Calender.