Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

date conversion from DD/MM/YYYY HH:MM:SS to YYYYMM

Tags:

date

oracle

i want to convert date to some other format.

Below is the example 04/03/10 09:00:50.000000000 AMto YYYYMM

Iam not able to get this , below is the query which i used to convert.

select to_char(to_date('04/03/10 09:00:50.000000000 AM','MM/DD/YYYY HH:MM:SS AM'),'YYYYMM') from table;

Iam getting exception as below

ORA-01810: format code appears twice 01810. 00000 - "format code appears twice"

like image 647
developer Avatar asked Nov 21 '14 07:11

developer


People also ask

How do I change Excel date format from YYYY MM DD HH MM SS?

In an Excel sheet, select the cells you want to format. Press Ctrl+1 to open the Format Cells dialog. On the Number tab, select Custom from the Category list and type the date format you want in the Type box. Click OK to save the changes.

How do I convert a date to Ddmmyyyy in Excel?

First, pick the cells that contain dates, then right-click and select Format Cells. Select Custom in the Number Tab, then type 'dd-mmm-yyyy' in the Type text box, then click okay. It will format the dates you specify.

How do I convert date format in Excel?

Select the cells you want to format. Press CTRL+1. In the Format Cells box, click the Number tab. In the Category list, click Date, and then choose a date format you want in Type.


1 Answers

  1. Format Code for Minutes is MI, not MM. MM is for months.
  2. You are using 2-digit year. Better to use RR for this. Even better use 4-digit year.
  3. TO_DATE doesn't store fractional seconds. You need to use TO_TIMESTAMP and use the FF as format code.

So, your query would be

select to_char(to_timestamp('04/03/10 09:00:50.000000000 AM','MM/DD/RR HH:MI:SS.FF9 AM'),'YYYYMM') 
from table;
like image 67
Noel Avatar answered Nov 04 '22 19:11

Noel