DATE FORMAT IN SQL

Hi
I need to compare between 2 dates and display the greatest among them.
Ex:
Date1 : 05/09/08 13:50 MDT
Date2 : 06/09/08 13:50 CDT
The greatest among these two is 06/09/08 13:50 CDT . But here I need to display
Date with Time stamp . like the output format should be "06/09/08 13:50 CDT"
Any body have any Idea about how to write Sql for this?

Please, take a look in the doc :
http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/functions134a.htm#1032202
Nicolas.

Similar Messages

  • Date format in SQL statements

    Hi there !
    Please, can anyone help me find out what is going on with date format in my SQL Statements ?
    While in development, the date format in SQL statements were:
    SELECT DATA_FIELD FROM TABLE WHERE DATE_COL = '10-DEC-2004'
    And works fine.
    After deploy to production server, we get ORACLE error: not a valid month
    So we change the format to
    SELECT DATA_FIELD FROM TABLE WHERE DATE_COL = '10/12/2004'
    And it gets to works again.
    Yesterday, the net administrator updated the JAVAC / JSDK run-time with Java update tool, and AGAIN we get ORACLE error: not a valid month
    So we change the format AGAIN to
    SELECT DATA_FIELD FROM TABLE WHERE DATE_COL = '10-DEZ-2004'
    And it gets to works again.
    What is going on ?
    JAVAC running on Windows2003.
    The application access the ORACLE DB directly through JDBC.
    There is no APPLICATION SERVER, like TOMCAT.
    The regedit (windows registry) ALWAYS was and are now :
    NLS_DATE_FORMAT = DD-MON-YYYY
    NLS_LANG = AMERICAN_AMERICA.WE8ISO8859P1
    Versions:
    DB Oracle 9.2.0.5.0
    JavaC 1.4.2.05
    Thanks.
    Juliano

    Somewhere, I'm willing to wager your NLS_DATE_FORMAT was/ is being changed. This is a client-side setting. Are you sure that the setting is the same on every client machine.
    This is one of the reasons that it is considered bad form to rely on implicit conversion. If you wrap your string literal in a TO_DATE, use the JDBC escape sequence {d }, or use a Date bind variable, you don't have this problem. The bind variable approach will also play much more nicely with your database's shared pool.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Date formats for SQL statements used by recordset object

    Hi,
    Date formatting appears to be quite problematic for Business One.  I did a forum search for date issues and I don't think I saw any of them with an "answered" status.  I have an issue with formatting a date for the creation of an SQL statement that the DI sends to SQL Server 2005.  I need to format a date so that the localization parameters don't matter for either the client machine or SQL Server's machine.  We don't have a problem as long as our machines are localized as USA.
    I have PL 22 and I have a form - ours - where I use the Today() function to fill a date field.  So this is a date that is not entered by the user.  The result of this function is consistent with the localization parameters on my machine.  We have two other date fields on the form where the user must type in the date. 
    As a test, I changed my machine to the UK parameters.  I then set up the language parameters of Business One for English(United Kingdom).  I changed the date format specifications in Business One so that its format is dd/mm/yy.  I then brought up the form and the field that is formatted by the above function arrived in the form's field as dd/mm/yy.  I then typed in the two other dates in the same format and added the record to the database.  The form's table is user-defined. 
    I dismissed the form then brought it back up loaded with the new record.  The date that was entered by the function appeared in USA format (mm/dd/yy).  The dates that were typed in appeared in the Business One format (dd/mm/yy).  This of course is not consistent.
    When I looked at what got into the database, the formats were the opposite.  Weird!  To make matters really confusing, I run an SQL statement within SQL Server Mgt Studio, and use the WHERE clause to filter on the date that was based on the function.  It didn’t matter what format I used for the WHERE clause, the record came up.  Does anyone have any idea about how I can ensure that I always use the correct date format for SQL statements passed by Business One to SQL Server regardless of where in the world the application is being run?
    Thanks,
    Mike

    Ian,
    Here's what I'm concerned about:  I’m using the date in a “WHERE” clause.
    Assume the date is Aug 3, 2007.
    "SELECT * FROM Table WHERE StartDate > ‘8/3/2007’"
    OR
    "SELECT * FROM Table WHERE StartDate > ‘3/8/2007’"
    If the client machine is set up as USA, the today function will provide the date as formatted in the first query.  If the database server is setup as let’s say the UK, I believe that SQL Server query parser will interpret the date as Mar 8, 2007.
    If the client machine is set up as UK, the today function will provide the date as formatted in the second query.  If the database server is setup as let’s say USA, I believe that SQL Server query parser will also interpret the date as Mar 8, 2007.
    In both cases it would be wrong.
    I know I could use the DATEPART function to get the three parts and this will make the code indifferent to the localization specs of the client machine.  I need to then be able to concatenate those date parts for the “WHERE” clause so that the localization specifications of the database server don’t matter.
    Thanks,
    Mike

  • Update date format in SQL developer

    I need to convert date format in SQL developer , it's varchar2 format now
    The current format is yyyy/mm/dd-hh:mm:ss:sss and I need to convert it to yyyy-mm-dd hh:mm:ss CST
    I don't really know SQL but did some research and found that I can use instr to find the string and replace it, however, no matter what I try,there is always something off :(
    Could anyone here help me with it? thanks in advance.

    create table xo_custom_date_format (mydateAsChar varchar2(100));
    table XO_CUSTOM_DATE_FORMAT created.
    insert into xo_custom_date_format
    values ('2012/03/23-09:52:24:123')
    +1 rows inserted.+
    select mydateasChar from xo_custom_date_format
    mydateaschar
    +2012/03/23-09:52:24:123+
    select to_timestamp(mydateaschar, 'YYYY/MM/DD-HH24:MI:SS:FF3') mydateAsTimestamp from xo_custom_date_format
    -- We must convert to timestamp data type, rather than date data type as you have fractions of seconds
    mydateAsTimestamp
    +23-MAR-12 09:52:24.123000000 --<-- This will probably appear differently, depending on your database NLS_ settings (i.e. what country you are in)+
    select to_char( to_timestamp(mydateaschar, 'YYYY/MM/DD-HH24:MI:SS:FF3') , 'YYYY-MM-DD HH24:MM:SS')||' CST' as myDateReformatted
    from xo_custom_date_format
    mydateReformatted
    +2012-03-23 09:03:24 CST+

  • EA1 - Cannot Change Date Format in SQL Results

    In version 1.2, I used to go to Tools > Preferences > Database > NLS Paramters and change the date format there. The change would then be reflected in the SQL results for date columns.
    When I try to do the same thing in 1.5 EA1, the date format is always the same, DD-MON-RR, no matter what I put in the date format setting under NLS Paramters.
    Am I missing something?
    Thanks.

    Just a quick post to make sure that the bug you logged takes into account all NLS parameters :), as this does not concern only dates but also timestamp formats, decimal and group separators as well, and probably all of the NLS parameters I assume.

  • How to convert from ifs date format to sql based dates

    I want to write a sql query using dates, to search an ifs
    database. Ifs stores dates as numbers created using the
    java.util.Date class. These dates are accurate to seconds.
    PLSQL uses a different format.
    What I need is a PLSQL function that converts PLSQL date format
    to and from the java.util.date format.
    This is an example of what I would like to do.
    String classname = "DOCUMENT";
    String whereclause = "CREATEDATE > theNeededFuction(to_date('01-
    Jan-2001', 'DD-Mon-YYYY'),'j')";
    Selector mySelector = new Selector(login.getSession());
    mySelector.setSearchClassname(classname);
    mySelector.setSearchSelection(whereclause);
    I do realize that I could simply convert the date in java, but
    in the long run, I want to use the oracle tools that support
    busness day calulations.
    -Mitch

    Hi Mitch - our ViewSpecification functionality automatically
    includes an Oracle Date column, which is derived from the java
    date values we store. These views are the supported way of
    performing read-only operations against an iFS instance.
    For yor reference, the Oracle date column is derived using the
    following SQL operation (e.g. for createdate):
    to_date('01-JAN-1970', 'DD-MON-YYYY') + (createdate/86400000)
    regards,
    dave

  • Wrong Date format in SQL Server

    Hello All,
    I have an asp page with a hidden field that holds
    <%=Date()%>. Because the
    Session.LCID is set to UK this value today would be
    12/03/2007 (UK format).
    When this hidden field is fed into an INSERT Stored Procedure
    in SQL Server
    in my testing environment, the date format that is inserted
    into the
    database is the same as the value in the hidden field eg
    12/03/2007, which
    is what I want.
    Now though, the site has moved to a production web server
    with SQL Server.
    When I perform this exact insert using the same webpages and
    (from what I
    can see) the same SQL Server configuration, the date inserts
    as 03/12/2007,
    US format. This is causing me big problems as the website is
    complete but
    the wrong dateformat is producing some undesirable results.
    The whole site
    is set up to expect the original format and I cannot see why
    this is
    happening.
    Does anyone have any suggestions and more importantly how I
    can change this
    please.

    There is a real issue here and it has nothing to do with the
    way that data
    is formatted on the way out.
    msSQL does seem to always assume that numbers entered in the
    format of
    00/00/00 follow the pattern of MM/DD/YY which is American
    format. So the 8th
    of March entered in UK format of 08/03/2007 ends up being
    intrepreted by SQL
    as 3rd August. However it only does this up to the 12th of
    each month. If
    you enter the 13th of March as 13/03/2007 SQL stores it
    correctly.
    The workaround does seem to enter the number in the
    YYYY-MM-DD format as
    Julian has suggested.
    Paul Whitham
    Certified Dreamweaver MX2004 Professional
    Adobe Community Expert - Dreamweaver
    Valleybiz Internet Design
    www.valleybiz.net
    "Lionstone" <[email protected]> wrote in
    message
    news:[email protected]...
    > SQL Server does not store dates in any format. They are
    simply numbers,
    > with the integer part representing date and the
    fractional part
    > representing time. If you do not format dates on the way
    out, then you're
    > leaving things up to your web server (and depending on
    when the dates
    > become strings, it might be the ADO provider and not ASP
    that does the
    > formatting).
    >
    > The only way to reliably format dates the way you want
    is to do so
    > explicitly. You may use CONVERT for SQL Server and
    specify a format
    > option (
    http://msdn2.microsoft.com/en-us/library/aa226054(SQL.80).aspx),
    > or you may use the FormatDateTime function in your ASP
    page.
    > FormatDateTime is locale-aware when it formats dates.
    All you have to do
    > is make sure the locale is set properly (which you seem
    to have done).
    >
    >
    >
    > "TTal" <[email protected]> wrote in message
    > news:[email protected]...
    >> Hello All,
    >>
    >> I have an asp page with a hidden field that holds
    <%=Date()%>. Because
    >> the Session.LCID is set to UK this value today would
    be 12/03/2007 (UK
    >> format).
    >>
    >> When this hidden field is fed into an INSERT Stored
    Procedure in SQL
    >> Server in my testing environment, the date format
    that is inserted into
    >> the database is the same as the value in the hidden
    field eg 12/03/2007,
    >> which is what I want.
    >>
    >> Now though, the site has moved to a production web
    server with SQL
    >> Server. When I perform this exact insert using the
    same webpages and
    >> (from what I can see) the same SQL Server
    configuration, the date inserts
    >> as 03/12/2007, US format. This is causing me big
    problems as the website
    >> is complete but the wrong dateformat is producing
    some undesirable
    >> results. The whole site is set up to expect the
    original format and I
    >> cannot see why this is happening.
    >>
    >> Does anyone have any suggestions and more
    importantly how I can change
    >> this please.
    >>
    >
    >

  • Multiple date formats using sql developer

    Hello!
    i have 2 date fields in a table.. one is populated using trunc(<date1>) and the other is to_date(<date2>,'YYYYMMDD HH24MISS'). We want <date1> to display as MM/DD/YYYY and <date2> to display as MM/DD/YYYY HH:MI:SS AMPM. When we set the date format under Preference -> Database -> NLS parameter in SQL Developer with a time format it adds 12:00:00 to <date1>, if we take it out, it drops the time in <date2>. What can we do?
    thanks!

    I think what the original poster wanted was to display the two date columns using different formats in the table "Data" tab and AFAIK that is not possible. Setting a date format in the Preferences accomplishes the same thing as the statement
    ALTER SESSION SET NLS_DATE_FORMAT='<some format>';
    in command-line SQL*Plus. To do what the OP wants they'll need to create a view that has a SELECT something like this:
    SELECT TO_CHAR( date1, 'YYYY-MM-DD' ) date1
    , TO_CHAR( date2, 'YYYY-MM-DD HH24:MI:SS') date2
    FROM some_table;
    One thing the OP needs to keep in mind is that the DATE datatype stores both date and time together. If they insert a date alone, the time defaults to midnight. (This is stated in the Oracle SQL Reference.)
    Ed. H.

  • Date Format in SQL Loader

    Dear All,
    I have a table CMS_HO where I have defined different columns. One column is of date type STATUS_DATE. I want to upload one ASCII file where one field is in the format like below:
    5/26/2008 12:41
    5/26/2008 8:51
    5/28/2008 9:01
    5/28/2008 13:54
    5/13/2008 10:45
    4/6/2008 9:21
    I want to upload file into Oracle database. Currently I am using following control file:
    LOAD DATA
    INTO TABLE CMS_HO TRUNCATE
    FIELDS TERMINATED BY "\t"
    TRAILING NULLCOLS
    ( ID,EXPIRYDATE, VER, SN, STATUS_DATE)
    There seems error in the STATUS_DATE field in control file. Can any one help how to modify this Control file so that data against this field can be uploaded into date format please?
    Thanks

    Here's an example i pulled from the web on specifying the date format in a control file.
    http://infolab.stanford.edu/~ullman/fcdb/oracle/or-load.html#loading%20date%20data
    Based on the sample data you provided, i think this is the format you're after.
    ME_XE?select
      2     to_date('5/13/2008 10:45', 'mm/dd/yyyy hh24:mi') as date_value_24_hours
      3  from dual;
    DATE_VALUE_24_HOURS
    13-MAY-2008 10 45:00
    1 row selected.
    Elapsed: 00:00:00.89

  • How to convert milliseconds to date format in sql query

    Hi All,
    The following code is in java.     
    String yourmilliseconds = "1316673707162";**
    Date resultdate = new Date(Long.parseLong(yourmilliseconds));
    could you plese tell me how to convert milliseconds into date format in query and comparing with another date like(sysdate-3)

    Hello,
    http://stackoverflow.com/questions/3820179/convert-epoch-to-date-in-sqlplus-oracle
    Regards

  • Help with date format and sql

    Hi
    I am a complete oracle idiot.
    I have created a table with 2 columns po_id,po_date. Yhe id data type is number,date type is date. To add values to the table i enter something like
    "insert into purchase_orders(po_id,po_date) values(1,01/01/2004)"
    It does not accept the date and will not add the record, i have also tried the date format 01-Jan-2004.
    What is the proper way to add the date.
    Thanks
    Garry

    You probably want to use an explicit to_date cast. That lets you specify the format of the date string, i.e.
    INSERT INTO purchase_orders( po_id, po_date )
      VALUES( 1, to_date( '01/01/2004', 'DD/MM/YYYY' );Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Checking correct data format using sql query

    1) I got column date of joining which accepts date in below format
    DD-MON-YYYY
    DD-MON-YY
    MON-DD-YYYY
    MON-DD-YY
    Month DD,YYYY
    Question:- how do i check whether all dates in Date of joining column are in above format or not using sql query?
    2) I got one more date column which accepts date in below format
    MMDDYYYY
    YYYYMMDD
    MM/DD/YYYY
    MM/DD/YY
    YYYY/DD/MM
    Question:- how do i check whether all dates in date column are in above format or not using sql query?
    sorry if it is a very simple question since I am new to sql and trying to learn ......Thanks for the answers from the group............

    In short, NO, it's not possible.  If you store dates correctly in the database as DATE datatype then you don't have this problem.  If you store them as VARCHAR2 you have a problem.
    So, you get a date of 20092012
    Is that 20th September 2012?  or is it 20th December 2009?
    What about...
    11-Jan-12
    Is that 11th January 2012 or 12th January 2011?
    Dates should never be stored on the database as strings.  That is why Oracle gives you a DATE datatype so you can store them properly.
    Also, when dates are passed from an application to the database, the application should be passing them as DATE datatype, and the application interface should be designed to accept dates from the user in a format specific to their country/locality and it would then know what that format is and automatically convert it to a DATE datatype before it gets anywhere near the database or any SQL.

  • Problem in converting util date format to sql date format

    im trying to convert util date to sql date...i'm getting the error msg as
    Error is : java.lang.NullPointerException
    Error Message : null
    i'm not bale to track the result...whatz the problem with this code?
    This fromDate value will be dynamically built, value will be
    fromDate="Tue Jul 15 00:00:00 IST 2003";
    java.util.Date xx=util.stringToDate(fromDate);
    java.sql.Date sqlD=null;
    sqlD.setTime(xx.getTime());
    System.out.println("sqld"+sqlD);

    I try this and it works:
    SimpleDateFormat simpledateformat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.UK);
    String s = "Tue Jul 15 00:00:00 IST 2003";
    java.util.Date date = simpledateformat.parse(s);
    java.sql.Date sqlD=new java.sql.Date(date.getTime());
    System.out.println("sqld"+sqlD);
    Hope this helps.

  • Date formatting in sql query

    hi,
    plz need hpl for this
    i have this query :
    q = "select count(*) from logs where dateLog=current_date";i have a logs in this current date but i havn't any data output ?

    Show us more of your code, please--especiall the spot where you read data from the ResultSet.

  • Date Format in SQL*Plus

    How can I change SQL*Plus to run the statement:
    select * from t_1 where t_1.date_ini = '22-05-2001'
    Thank You

    I had this problem the other day and with a lot of toll and trouble I figured it out.
    select * from dual where to_date(t_1.date_ini,'DD-MM-YYYY') = '22-05-2001'
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Miguel Miqambres ([email protected]):
    How can I change SQL*Plus to run the statement:
    select * from t_1 where t_1.date_ini = '22-05-2001'
    Thank You<HR></BLOCKQUOTE>
    null

Maybe you are looking for

  • Why is it taking so long to install lion upgrade

    why is it taking so long to install lion upgrade? It is about 20 minutes now and still saying wait a few minutes

  • Error when sending message: 500 Internal Server Error

    Hi IE is not accepting any messages, when I try to send the messgae to the IE ( using RWB) i am getting the below error " Error when sending message: 500 Internal Server Error". following things what i have noticed. 1. Pipleline URL is fine, both in

  • Tracking of Assets taken on Lease

    Hi, can you please suggest better way of tracking the assets which were taken on Lease. For some of them depreciation needs to be calculated, & for some are not required. please suggest..... regards, Shekar

  • Oracle GoldenGate 11.2 integration with hadoop

    Hi All, We are trying to bring in data from some external source into Hadoop environment using Oracle GoldenGate. I have read in some forums that OGG provides some sort of custom built java API's as integration options for Big Data Analytics. My ques

  • Internet Exploder

    I figure this is hte closest I can get to a section on this. I need to use a website that requires Windows and Internet Explorer. I've got Explorer 5.2 on my iBook, but obviously Windows isn't an option on it. So, I was wondering if there's any way t