Convert varchar2 string to date - Oracle SQL Developer [duplicate] - sql

This question already has answers here:
Need help converting date in format 20120130 to Date data type oracle sql
(4 answers)
Closed 6 years ago.
Need to covert VARCHAR2 string in format of 20150101, 20150102, 20150125.....etc into date in format of 01/01/2015, 01/02/2015.... etc.
AND update TABLE DATA
ORACLE11G MY SQL DEVELOPER
ALL HELP APPRECIATED!!! LIFE SAVER
COMPLETE SQL PL/SQL NOOB!

Just use to_date() that is what it is there for:
select to_date(col, 'YYYYMMDD')
If you then want to format this, you can use to_char():
select to_char(to_date(col, 'YYYYMMDD'), 'DD/MM/YYYY')

Related

Convert date in string format to date data type [duplicate]

This question already has answers here:
Amazon Athena Convert String to Date
(2 answers)
Closed 3 years ago.
I would like to convert date in string format ‘mmddyy’ (120618) to date and find the max of date in an Athena table. How can write this sql query ?
You can use date_parse() to convert the string into a date:
select date_parse('120618', '%c%d%y')
Therefore, you could use it like this:
SELECT
MAX(date_parse(date_field, '%c%d%y')) as dt
FROM table
See: Date and Time Functions and Operators — Presto Documentation
By the way, you should tell whoever made that original data format that it is a poor way to store dates. ISO format is better (eg 2018-12-06).
Can't you just output your date by using the ORDER BY , plus ASC | DESC (depends on what you mean by "max of date"), command and just use the first output you get? By using LIMIT?

Best way to convert Date Format in SQL from yyyymmdd to yyyy-mm-dd format [duplicate]

This question already has answers here:
How to get a date in YYYY-MM-DD format from a TSQL datetime field?
(25 answers)
Closed 5 years ago.
I have a bunch of dates in the format yyyymmdd without the "-" separated. What is the easiest way to change to yyyy-mm-dd format using only SQL with read access only.
i.e 20111230 -> 2011-12-30
One line or optimal performance solution preferable that works in Microsoft SQL
DECLARE #dtr VARCHAR(25) = '20111230'
SELECT CONVERT(char(10),CAST(#dtr AS DATE),126)
-- sqlserver 2012
SELECT FORMAT(CAST(#dtr AS DATE),'yyyy-MM-dd' )

SQLITE date formate [duplicate]

This question already has answers here:
Sqlite convert string to date
(9 answers)
Reformat dates in column
(2 answers)
sqlite change date format of every cell in column
(1 answer)
How can I convert the Date format for column in sqlite table?
(1 answer)
Closed 5 years ago.
I am currently working on a project that utilizes SQLite. I need to covert a stored date format from MM/DD/YYYY to YYYY/MM/DD. However, I don't know how to convert in SQLite.
Please take a look here:
https://sqlite.org/lang_datefunc.html
What you need is strftime function to specify the format.

Date Difference in Days [duplicate]

This question already has answers here:
Calculating difference between two timestamps in Oracle in milliseconds
(11 answers)
Closed 8 years ago.
I'm trying to find the difference between a TIMESTAMP(6) field and a DATE field in oracle sql to return number of days.
Anyone know how to convert these?
i tried to_date, to_number and a few other functions. I actually got it to work by using trunc on my datetimestamp
(a.date- trunc(b.datetimestamp))

Oracle timestamp in number format SQL [duplicate]

This question already has answers here:
Convert Unixtime to Datetime SQL (Oracle)
(2 answers)
Closed 9 years ago.
I have my datetime column in table defined as Oracle NUMBER data type which contains data in this format 1363709957 for example.
I want to get these numbers in query so i can execute my insert scripts which will put in current time in there. What is the oracle SQL for that?
Your time stamp appears to be a standard Unix time stamp. You need to use arithmetic to convert this here's a post on OTN about this,
and one for the other direction.