Issue Date format as a VARCHAR

Using Oracle 10 g:
I have a varchar field that keeps a date like:

2010-08-28 14:40:21

I am trying to format the date so I can check if it is greater than the sysdate. I'm doing:

To_char (end_date, 'YYYYMMDD') > to_char (sysdate, 'YYYYMMDD');

I get an error message:
ORA-01722: invalid number
01722 00000 - "invalid number."

Which makes sense, but I'm not sure how to properly format the end_date in YYYYMMDD format.

Hello

user9179751 wrote:
Using Oracle 10 g:
I have a varchar field that keeps a date like:

2010-08-28 14:40:21

I am trying to format the date so I can check if it is greater than the sysdate. I'm doing:

To_char (end_date, 'YYYYMMDD') > to_char (sysdate, 'YYYYMMDD');

I get an error message:
ORA-01722: invalid number
01722 00000 - "invalid number."

Which makes sense, but I'm not sure how to properly format the end_date in YYYYMMDD format.

Is the VARCHAR2 column end_date?
To_char, as its name suggests, converts a DATE to a string of record CHAR. If you already have a string of characters, so there's no need of TO_CHAR.
You can call TO_DATE, such as

WHERE   TO_DATE ( end_date
                , 'YYYY-MM-DD HH24:MI:SS'
                )  > SYSDATE

but it is more effective and less prone to say

WHERE   end_date > TO_CHAR (SYSDATE, 'YYYY-MM-DD HH24:MI:SS')

Why is it more effective? The optimizer considers SYSDATE be a constant, even if the query takes a long time. Therefore, it only will convert SYSDATE in a string once, even if you have 1 million rows in the table. If you did the first way, you must call TO_DATE a million times, once for each line. In addition, your column, end_date, being alone on one side of the > operator, the optimizer can use an index on that column.
Why is it less error-prone? If you still have a line where End_date is incorrect, you will get an error if you call TO_DATE. Not try to convert end_date, you won't make mistakes.

This works because the format for End_date is suitable for sorting. If the format was, say, 'DD-Mon-YYYY', you would have to be converted to a DATE.

It would be better if End_date a DATE column. It is never a good idea to use a VARCHAR2 column to store points in time.

Tags: Database

Similar Questions

  • Date formatting to_char - truncate issue zeros

    Hello

    I have used this date formatting in an APEX application, but I noticed that the problem also occurs when you run a simple script in the database.

    The query is:

    Select

    TO_CHAR (sysdate, 'fmDay, GFMD fmMonth AAAA HH:MIPM'),

    TO_CHAR (sysdate, ' HH:MIPM of MON-DD-YYYY "")

    of the double

    The problem occurs when the minutes have a zero in it, in the example that I have attached, it was 14:05, and it shows as 14:05

    https://plus.Google.com/u/0/photos/104459804528712563956/albums/5958573459391223345/5958573462256341170?PID=595857346225...

    Is there a reason that this is happening? I am unable to use the combination I've used? I really want the full date with month and day names.

    Version of DB: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0

    Amanda.

    Just add fm with the time format:

    SQL > select

    2 to_char (sysdate, 'fmDay, GFMD fmMonth AAAA fmHH:MIPM')

    3 double;

    TO_CHAR (SYSDATE,'FMDAY, FMDDFMMONTHYY)

    ------------------------------------

    Wednesday, December 18, 2013 09:03

    Concerning

    Girish Sharma

  • mask for the format issue date

    I was wondering why this first query works, but the second does not work, if someone could help please :

    [quote]

    SELECT course_no, section_id, to_char (start_date_time, 'Day' The "Ddspth" of "fmMonth yyyy") IN the section

    WHERE to_char (start_date_time 'DY') = 'Sun '; [/ quote]

    [quote]

    WHERE to_char (start_date_time, 'Day') = 'Sunday '; [/ quote]

    any ideas? can't see what I'm missing?

    Thanks in advance,

    Nick

    Date format day returns the name of the white day to the length of the longest day name (in the appropriate language):

    SQL > select ' [' | to_char (sysdate + 1, 'day') |] ']' double.

    '['|| TO_CHA
    -----------
    [Sunday]

    SQL > select ' [' | to_char (sysdate + 1, 'FMDay') |] ']' double.

    '['|| TO_CHA
    -----------
    [Sunday]

    SQL >

    Use FM modifier and,'nls_date_language = English "to make independent NLS:"

    WHERE to_char (start_date_time 'FMDay', 'nls_date_language = English') = 'Sunday ';

    SY.

  • problems by analyzing a date format string...

    Hi all, I'm having a hard time to convert a date into a string.

    I was using to_char but after much research, I thought that it would be better to use convert so I do:

    SELECT CONVERT (VARCHAR (8), 'November 19, 2012', 112) twice;

    Where the specifications for 112 is YYYYMMDD but I get the error "ORA-00936: lack of expression ', guess is cause Oracle do not know how to read the string to be converted.

    How can I convert a YYYYMMDD string format string of the form dd mmm yyy (as described above)?

    Thanks in advance,

    It seems that your search will lead you to a SQL Server thread. SQL Server uses arbitrary numbers to represent date formats. Oracle does not - the number 112 is irrelevant for Oracle.

    In Oracle, you convert a date to a string using the function TO_CHAR

    SELECT to_char( date '2012-11-19', 'YYYYMMDD' )
      FROM dual
    

    Of course, this assumes that you start with a date (like I do with my date literal). If you start with a string representing a date and you want to convert it to a string that represents the same date in a different format, you will need to use a TO_DATE and a TO_CHAR to convert the original string to a date and date on another string

    SELECT to_char( to_date( '19 Nov 2012', 'DD Mon YYYY' ), 'YYYYMMDD' )
      FROM dual
    

    Justin

  • Variable Date format of presentation

    Hi all try to format a variable presentation from a Narrative perspective, is it possible that this can be done by using javascript or html that I can stick in narrative mode.

    I want something like ' the date used is @{indate} to the end of the month.

    Date format must also be JJ.mm.aaaa... his currenty displayed as yyyy/mm/dd... I don't want to add the columns in my report and hide as there seems to be a performance lag when I do this.

    Any ideas... Java gurus out there.

    I tried @{indate} [dd.mm.yyyy..] but it does not work.

    See you soon

    Jenny

    Published by: user5470064 on August 18, 2011 09:58

    Published by: user5470064 on August 18, 2011 09:59

    Here you go...

    I tried in my machine and its working very well...

    In the answers--> in the criteria TAB, in the column fx use under formula...

    «case when 1 = 1 then EVALUATE ('TO_CHAR(%1,%2)' as a varchar (20), date ' @{pv_date} {1998-07-05} ',' dd.mm.yyyy "") else ' ORE time Dim ".» End of the name of the month.

    pv_date is the variable of presentation and

    For "ore time Sun. "" MNTH name ' use any column of varchar data type ...

    Hope that's helpful...

    Thank you
    Ashish Gupta

  • In the results pane date formats

    I am troubleshooting a data corruption issue, and I need to see year-round in the developer sql results pane. When I issue a select statement on a table dates in the format DD-MON-AA results pane. Is there a way to display dates in the format DD/MM/YYYY.

    Hello

    You who control with tools | Preferences | Database | NLS | Date format. Alternatively, a spreadsheet on your connection, just run

    ALTER session set nls_date_format = "DD/MM/YYYY";

    The alter session actually overrides the preference setting and applies to all spreadsheets shared for the connection and also includes the results of the data object browser tab.

    Kind regards
    Gary Graham
    SQL development team

  • How to change the date format in OBIEE

    Hello

    I have a need to change the column to a column of varchar by OBIEE...

    The date column stores the data in the format "YYYY/MM/DD", I need to change that for a column of varchar with this format "YYYYMM"...

    Since I'm pointing directly to the transactional database, I can't make changes to the database level, so I have to do in OBIEE layer, of the ideas of how this could be done?

    Thanks in advance!

    Hi user,

    Reference: http://varanasisaichand.blogspot.com/2010/01/how-to-change-data-format-to-our-custom.html

    http://varanasisaichand.blogspot.com/2010/05/evaluate-function.html

    Thank you
    Saichand.v

  • insertion error - date format picture ends before the conversion while

    My system: I use of Oracle Database 10 g Express Edition Release 10.2.0.1.0 - product with SQL * more: Release 10.2.0.1.0 and the first thing I've done in this project is a user account configuration especially for her through Application Express 2.1.0.00.39 with all permissions and then connected with SQL * more and seized command and run scripts on it since.

    I got the following error was in a previous project, but I don't have the result of it so I don't know how much he touched me. We can not always distribute perfect projects so I could live with that. It is that this new project is the first that start from a previous one have of course, I still have the error so I think they'll be less forgiving of mistakes that I had more time to work on it. However, after hours of research & debugging tests I still cannot do things.

    I read on sites in development more than a couple that we should not rely simply on inputs of channel inserts on dates where there is incompatibilities with nls_date_format and based instead on TO_DATE. This seems logical and I have no problem of implementation, but there is a problem running it. :|

    The following is an excerpt from my project bringing the error that I need to move.
    Thank you so much for your help
    DynV

    H2.
    code

    ALTER SESSION SET nls_date_format = "DD/MM/YYYY";
    DROP TABLE EMP;

    CREATE TABLE EMP
    (
    NOEMP INTEGER NOT NULL PRIMARY KEY,
    NAME VARCHAR (15) NOT NULL,
    FIRST NAME VARCHAR (15) NOT NULL,
    NOFONCTION INTEGER NOT NULL,
    DATEEMBAUCHE DATE,
    SALARY INTEGER NOT NULL,
    NODEPT INTEGER NOT NULL-,
    -FUNCTION REFERENCES FOREIGN KEY (NOFONCTION),
    -FOREIGN KEY (NODEPT) REFERENCES DEPT
    );

    -NoEmp, name, NoFonction, DateEmbauche, NoDept, salary
    INSERT INTO VALUES EMP (1230, "DAHER", "ERIC", 1, TO_DATE (DECEMBER 17, 1997 ',' DD/MM/YYYY ""), 40, 20000);
    INSERT INTO VALUES EMP (3235, "LEMAY", "PATRICK", 3, TO_DATE (FEBRUARY 20, 1982 ',' DD/MM/YYYY '), 20, 3500);

    H2.
    result

    Modified session.

    Table created.

    INSERT INTO VALUES EMP (1230, "DAHER", "ERIC", 1, TO_DATE (DECEMBER 17, 1997 ',' DD/MM/A))
    YY'), 40, 20000)
    *
    ERROR on line 1:
    ORA-01830: date format picture ends before converting all of the input string

    INSERT INTO VALUES EMP (3235, "LEMAY", "PATRICK", 3, TO_DATE (FEBRUARY 20, 1982 ',' DD/M))
    M/YYY'), 20, 3500)
    *
    ERROR on line 1:
    ORA-01830: date format picture ends before converting all of the input string

    H1.
    solution

    The Xgc of channel for the IRC server freenode user [#sql | irc://freenode/%23sql] had me I was using 3 characters for my picture/mask/filter /... instead of the 4 that taking data. then they became "JJ/M".
    M/YYYY "."

    How small error but with such devastating consequences.

    Published by: user13420426 on December 6, 2010 01:39

    You're 1 shy O.

    TUBBY_TUBBZ?select TO_DATE('17/12/1997', 'DD/MM/YYY') from dual;
    select TO_DATE('17/12/1997', 'DD/MM/YYY') from dual
                   *
    ERROR at line 1:
    ORA-01830: date format picture ends before converting entire input string
    
    TUBBY_TUBBZ?select TO_DATE('17/12/1997', 'DD/MM/YYYY') from dual;
    
    TO_DATE('17/12/1997'
    --------------------
    17-DEC-1997 12 00:00
    
    1 row selected.
    
    TUBBY_TUBBZ?
    

    Notice how I YYYY where you YYY.

  • Date formatting according to UTC time zones

    Using MySQL, php

    www.freecrm.x10hosting.com

    Before installing my paintings, I need to better understand the relevance of the datetime property and conversion of this area.

    I am based in th UK (UTC, Greenwich mean time), but my host is in the States, which means that the date of "now" and time is based on US time (UTC?)-

    I did the formatting of the date, for example <? PHP echo date (, d/m/Y ', strtotime ($datetime ['DATETIME']));? > but don't know how to approach the problem compared to all visitor's time zone in the world.

    I have a sniffer script that detects the language of browsers, but I don't see that to be very useful.

    The site requires registration/login so I guess I could have a preference of UTC (UTC + 3 or whatever) in their folder. This could then be used to something like that.

    <? PHP date echo (se, d/m/Y ', strtotime($datetime['DATETIME']+$row_recordsetuser['UTCTIMEZONEPREFERENCE']));? >

    Does make sense?

    I know that the formatting will be a challenge as well because the United States use d/m/Y,

    Or is there a way to format the data of MySQL before its even called?

    .oO (RichardODreamweaver)

    > OK - think I have sussed it.
    >
    > All the date fields will be VARCHAR, with the Time() stored form function
    > Seconds UTC/GMT.
    >
    > The user can choose a preference for the time zone (GB, TCU, Etc/GMT + 1)
    >
    > In addition, the user can select a time format which is strored.
    >
    > Login, these preferences are stored as Session variables and used on each
    > page to set the time zone.
    >
    > putenv ("TZ =". $_SESSION ['timezone'] "")

    You must use date_default_timezone_set() instead:

    | Note: Since PHP 5.1.0 (when the date/time functions were written).
    | every call to a date/time function will generate an E_NOTICE if the
    | timezone isn't valid, and/or a level E_STRICT message if using the system
    | the parameters or the TZ environment variable.

    http://www.php.net/manual/en/function.date-default-timezone-set.php

    Micha

  • Data format of hyperlink

    I want to be in a position of the column in the query to access a certain URL, for example, suppose I have a column in the database containing data from URL in there, and I want the user to be able to access the URL for the report. I know I can use the data format 'Hyperlink', but I don't want the URL is displayed in this column, I want, for example, the value of 'Visit website' to appear and when the user clicks on this link, the underlying URL would be open in a separate window.

    somehow, I'm not able to view code... just text

    Replace "visit our Web site.

    '|| Cast (DealHeader.AnotherColumntobeshown as varchar (50)). »

    How your url is stored in the database column? Mine is stored as
    http://server/...

  • Edition of text column data Format database columns of answers

    Hello

    We use Oracle Business Intelligence Enterprise Edition v10.1.3.4 on the cube for OLAP Oracle 11 g. Reports we create have (among other things) columns with an underlying type of VARCHAR data in oracle tables.

    When we try to change the properties of such a VARCHAR column column, "Data Format" tab shows only 'Plain Text' as an option under the menu drop-down "Override default data Format". Options to display the text 'HTML' or 'LINKS', etc. are not available.

    All entries on what can be done in the answers or the repository to get these options for formatting of column data are highly appreciated.

    Thank you
    Piyush

    You set your HardenXSS to false in the instanceconfig.xml file? By default, OBIEE is set to true. Setting to false allows the HTML tags to appear as options for fields VAR. check it out here... Chapter 2, page 37.

    http://download.Oracle.com/docs/CD/B40078_02/doc/bi.1013/b31766.PDF

  • How to advocate for regional change of short date format

    This is something relatively trivial but annoying all the same, but I don't know where to go to advocate for change.

    Have just updated for Sierra and one of the first things I notice is the addition of a point at the end of the month in short date format, i.e. 'September 19, 2016'.

    "In Australia, as in the United Kingdom, the standard must not use this period - it should be just'19 Sep 2016", and in the past, that's how it appeared in OSX for the Australia. Don't know why the change.

    This abbreviation is not replaceable by the user, so where can I go to provide appropriate feedback and I hope to have this problem on the track?

    A solution is to make my default language and region of the United Kingdom, but do not know if there is a price to pay for it.

    You can provide feedback to Apple asking them to change it:

    www.Apple.com/Feedback

  • How do I change the date format in the section of the United States to the United Kingdom

    As in the question.

    Hello

    I had a glance in this and have found that Thunderbird uses the date format of your computer system. If you change it, it should be reflected in Thunderbird.

    I hope this helps, but if not, please come back here and we can look at another solution for you.

  • How can I configure the cell data format

    How can I configure data format of cell numbers: for example, I want to capture 123456.78 and need to be 12A3456.78?

    I tried to put #A # #. # format option, but it didn't work a few time and it became A123456.78.

    I also tried on excel and it worked very well, but I like the numbers better. is there a solution to this problem?

    Thank you

    HEY Chi - Lun,

    I don't think that this is possible as many number format. You should be able to insert A in a text string using a formula, but this would happen in a second cell, not that the number has been entered.

    "Assuming all the"numbers require the same inserted letter after the second number, this should do the work."number" entered in column A; the formula in column B. In the table below, your value as an example is A6.

    = Left (A, 2) & "A" & RIGHT (A, LEN (A) - 2)

    Kind regards

    Barry

  • Date format of messages is absolutely ugly

    Hi all.

    I'm really frustrated format of date/time of Messages on my iPhone6 (and also on my OS - X).

    What the main reason for the use of the words 'Today', 'Yesterday', 'Saturday' and other?

    Who need this lyrical sh * t? All my friends is also frustrated by this function, because if you need a specific date for the quote or shipping screen, you will need to do a lot of unnecessary travel.

    I mean - if you want to find something and need to translate "what the date was Saturday?", you need to go to calendar and look here, what date was Saturday.

    Apple !

    Please, I beg you! Make this switchable feature!

    This date format looks like completely unnecessary and useless decoration.

    Simply return the precise date.

    p.s. this message angry wrote after a misunderstanding with screenshots attached in the e-mail Messages.


    iOS version: 9.3.3

    The OS - X version: 10.11.6

    Not something anyone here can do for you. You can offer your comments Apple here.

Maybe you are looking for