-2
SELECT date, percent FROM errorpercent WHERE percent > 1;

   date    |        percent         
2016-07-17 | 2.26268624680272595600

I would like 2016-07-17 (as well as the potentially many other rows) to be converted to the format of July 17, 2016.

hc_dev
  • 8,389
  • 1
  • 26
  • 38
Jennifer
  • 1
  • 2
  • 4
    Date --> character conversion functions are notoriously database-dependent. – Gordon Linoff Jan 31 '19 at 19:05
  • 4
    When you use the SQL tag, there's a huge hint shown to you that suggests that you also include a tag for the specific DBMS you're using, as functionality and syntax varies between them. Why did you ignore that hint? We can't possibly answer this question until you've clarified the DBMS you're using, which means you're waiting longer for an answer than you should be. Please [edit] your post and add the tag for the specific database engine you're using, so you're not wasting both your time and our time on answers that may not work for youj. – Ken White Jan 31 '19 at 19:08
  • what data type is the column `date`? –  Jan 31 '19 at 19:59

3 Answers3

0

If you are using Oracle DBMS, then simpler way is to use to_Char function, for example then this query will be :

select to_char(date,'Month DD, YYYY') as new_date,
       percent 
  FROM errorpercent 
 WHERE percent > 1;
Rhythm
  • 680
  • 5
  • 9
0

Nearly all databases have their own date formatting functions.

See the many questions tagged , , , to learn more. You can also search stackoverflow for:<your database> date format

Following you will find solutions for the other 4 most commonly used SQL databases (besides Oracle already answered):

IBM DB2

.. then you can use VARCHAR_FORMAT scalar function. This works on LUW (Linux/Unix/Windows) as well as iSeries (formerly AS400) systems. Your SQL query would then look like this:

SELECT
  VARCHAR_FORMAT(date,'Month DD, YYYY') as formatted_date
, percent  
FROM
  errorpercent
WHERE
  percent > 1

See also:

MySQL

.. then you can use DATE_FORMAT scalar function. Your SQL query would then look like this:

SELECT
  DATE_FORMAT(date, '%M %D, %Y') as formatted_date
, percent  
FROM
  errorpercent
WHERE
  percent > 1

See also:

Microsoft SQL Server

.. then you can use CONVERT scalar function. Your SQL query would then look like this:

SELECT
  CONVERT(VARCHAR, date, 107) as formatted_date
, percent  
FROM
  errorpercent
WHERE
  percent > 1

See also:

PostgreSQL

.. then you can use TO_CHAR scalar function. Your SQL query would then look like this:

SELECT
  TO_CHAR(date, 'Month DD, YYYY') as formatted_date
, percent  
FROM
  errorpercent
WHERE
  percent > 1

See also:

hc_dev
  • 8,389
  • 1
  • 26
  • 38
0

If the column's data type is date then:

SELECT to_char(date, 'Month, DD, YYYY' ), percent FROM errorpercent WHERE percent > 1;

If it is a string then:

SELECT to_char(to_date(date, 'YYYY-MM-DD'), 'Month, DD, YYYY' ), percent FROM errorpercent WHERE percent > 1;
forpas
  • 160,666
  • 10
  • 38
  • 76