Simple Dates Subtraction

Hello guis, i'm new here. I'm studying for iz0-051 certification exam and I would really appreciate if you can help me out with this doubt i have..
I know that a character literal can be implicitly converted to a date if it follows the mask '[dd,DD] separator [mm,MM,Mon] separator [yy,rr,yyyy] etc..etc...
then.. why doesn't this simple subtraction go through (number of days between a certain date and the current sysdate)?
select sysdate - '01-jan-2012' from dual;
it gives "ora-01722 invalid number" error, shouldn't it implicitly convert the literal to a date and then subtract it from sysdate? what am I doing wrong?
thanks for your help,
Paolo

Welcome to the forum.
(Don't forget to read the SQL and PL/SQL FAQ @ https://forums.oracle.com/forums/ann.jspa?annID=1535)
Oracle isn't considering implicit conversion that way (and that's a good thing).
You should never rely on implicit datatype conversions.
SQL> select sysdate - '01-jan-2012' from dual;
select sysdate - '01-jan-2012' from dual
ERROR at line 1:
ORA-01722: invalid number
SQL> select sysdate - to_date('01-jan-2012') from dual;
SYSDATE-TO_DATE('01-JAN-2012')
                     239.59963The other way around will not work either:
SQL> select '01-jan-2012' - sysdate from dual;
select '01-jan-2012' - sysdate from dual
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected CHAR got DATEThe documentation will tell you more details if you want to know:
http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements002.htm#g195937

Similar Messages

  • Date Subtraction

    I am trying to figure out a way to subtract dates to get age. If I were to enter my birthdate, I would like to calculate the age. I know how to get today's date but how does one due date subtractions?

    Oh goody! One of my favourite topics again!
    Beware of using getTimeInMillis() for date subtractions, because java doesn't always return the same number of milliseconds per day. Quite apart from the valid point that on days that daylight saving occurs you lose or gain an hour, there seems to be a difference of a few (up to 8) milliseconds from day to day. Don't ask me why - there just is! This is fine as long as you use floating point maths to divide the time difference in millis by the (theoretical) number of milliseconds per day, but if you use integer maths, you're likely to get problems. Also, as I just pointed out, daylight saving time needs to be taken into account.
    It's better to avoid using time-related functions and work purely from the Calendar class. I won't post the full code of my date difference method, because I don't have it on this computer, but basically, you need to look at things like getActualMaximum(int field) in the Calendar class to get the number of days in a month or year.
    If your days are in the same month, it's simple.
    If your days are in different months of the same year, add together the number of days remaining in the month of the first date, the lengths of all the months in between, and the day of the month in the second date.
    If your dates are in different years, use the day number in the year (I can't remember the Calendar field name - look it up), then add together the number of days remaining in the first year, the number of days in the intervening years, and the day number in the second year. I'm assuming the dates are not too far apart!
    You could do something clever with calculating the number of leap years between the two dates, but I was trying to be extremely general, rather than assuming the Gregorian calendar.
    I hope I haven't complicated things too much!
    Robin

  • Dynamic Drop Down creation using simple data types

    Hi all,
    I have got a requirement in which i have to create an iView which is going to have 6 drop down values and with in that 1 value is going to have sub values which needs to get displayed in the similar drop down fashion.
    I have created a simple data type having enumeration of the 6 values and linked the same to iView with drop down by key which is working successfully. And for the purpose of sub values i have created a similar simple data type with two values and linked the same with a value attribute.
    Well, can any one tell me the further process to proceed ?
    Thanks in advance ...
    Vipin

    Vipin,
    There are quite some steps to achieve what you need. Since you have both your DropDownByKey elements defined and bound to context elements, it may make sense to keep the Second DropDownByKey element invisible and make it visible only when user selects a specified key from first DropDownByKey. To achieve this, follow these steps.
    1. Create an action with a parameter "key" of type string.
    2. Bind this action with onSelect event of your First DropDownByKey UI Element.
    3. Do mapping of parameter "key" in your wdDoModifyView with following code.
      if (firstTime)
             final IWDDropDownByKey dk = (IWDDropDownByKey)view.getElement("DropDownByKey1");
               // Replace DropDownByKey1 with id of your DropDownByKey Element.
             dk.mappingOfOnSelect().addSourceMapping("key", "key");
    4. Create a context attribute of type WDVisibility say "DDVisible" and bind to "visible" property of your second DropDownByKey.
    5. Set DDVisible to NONE in wdInit().
    wdContext.currentContextElement().setDDVisible(WDVisibility.NONE); 
    6. In onSelect action write this code to make second visible
    if(key.equalsIgnoreCase("Two")){
         //Replace "Two" with your required value.
             wdContext.currentContextElement().setDDVisible(WDVisibility.VISIBLE);
           else{
                wdContext.currentContextElement().setDDVisible(WDVisibility.NONE); 
    This should give the desired results.
    Hope this helps.
    Vishwas.

  • Simple Date Format

    Hi,
    I have an entity object with some attributes, one of them is called "CREATED_ON", which i have specified as a history column (created on).
    I have specified a format type of Simple Date in my Control hint and a format of dd-MM-yyyy. I then created a view based on my entity and dragged the view as an adf creation form. I also dragged a commit button to commit my record.
    However, the date that is stored in my database have a non-zero time component (e.g. 10-JUL-2007 10:46:22). This is a problem becuase in my search form, the search criteria does not work (it requires the exact time also to work). I do not want to use TRUNC in my SQL query.
    Instead i want the date to be stored with the format mask that i have specified.
    Can you please help me?
    Thank you

    Do you really want to lose the time component altogether, or just make the query on date-without-time work?
    There would be no way of recovering the information about when during the day the row was created if you truncate the time information, but it's possible to achieve if that's what you want. Both are possible to achieve.
    To achieve the "losing the current time info forever" approach, add the following overridden method in your entity impl class that slightly changes the way the history attribute value is returned, in my case, for the HIREDATE attribute of an Emp example:
        protected Object getHistoryContextForAttribute(AttributeDefImpl attributeDefImpl) {
            Object ret = super.getHistoryContextForAttribute(attributeDefImpl);
            if (attributeDefImpl.getIndex() == HIREDATE) {
                ret = new Date(new java.sql.Date(((Date)ret).getValue().getTime()));
            return ret;
        }To achieve # 2 instead, just add a SQL-derived attribute to the view object with formula:
    TRUNC(HIREDATE)and then use that sql-derived attribute in the query form instead of the normal HIREDATE attribute.

  • What can be considered as the business logic of simple data entry form

    Hi all,
    I want to separate my applications logic into layers. It is a simple data entry form and doesn't contain any complex business logic. So I want to get this simple business logic to different layer. But the problem is, I cannot clearly identify what are business logic of this kind of simple data entry form.
    How do I separate business logic of this simple data entry form to another layer?
    any help is appreciated,
    Thanks in advance,
    Dil.

    dcminter wrote:
    It is a [form] and doesn't contain any complex business logic. So I want to get this simple business logic to different layer. But the problem is, I cannot clearly identify what are business logic of this kind of [form].Are you asking which bits are business logic?
    Suppose that the data comes into your system immaculate from some external system. Imagine that it will go out into some other system. The bits that you would still have to write are your business logic.That's a nice practical definition. Thank you, I'm stealing it.
    Also interesting to note that validation falls into that category... say you're recieving data from a magical external source... you still have to validate it.
    And of course you'd still have to store it somewhere, ans retrieve it.
    Yep, I definately like that definition.
    Cheers. Keith.

  • Simple Data Base Program for Mountain Lion

    Does anyone have a recommendation for a simple data base program that will import comma delimited fields from early versions of Filemaker Pro (v 3.0, v5.0)
    The ability to import Filemaker Templates and Layouts would be a big plus.
    I do not need the a highly sophisticated program just something with the ability to import data from several different data bases and create layouts that look like I want them to look.  
    Also what is the earliest version of Filemaker that will run well on Mountain Lion ?
                                                                            Thanks....Ken

    I suggest Bento (by Filemaker), simple database, imports Filemaker Pro files and doesn't cost very much

  • Simple Data Type in CAF of SAP NetWeaver DevStudio 7.1 SP3

    Hallo
    Anybody knows about the use of Enumeration for simple Data Type in CAF of SAP NetWeaver DevStudio 7.1 SP3?
    I've defined an attribute "status" for the Entity "Project" with the following values
    0: NEW;
    1: ACTIVE;
    -1: INACTIVE. 
    As you see the data type is short.
    In the program I want to use the following code:
    Project myProject = new Project();
    myProject.setStatus(Status.NEW)
    But I found it out, it is inpossible to to use Status.NEW.
    On the other side I read the article of https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/085098ea-0c01-0010-12a8-80ac838bec85. This article is again not updated with the version 7.1 SP 3.
    I cannot understand about the whole changes. In the previous release we can define a DDIC type and use it as Simple Data type and in the new Release we just use the XSD-Facet to define an enumeration, but the problem is: we can not reference it in the program. I don't see any advantage.  And I tried to find out how I can define the attibute using DDIC type. I didn't get it.
    Thanks for any Hints!
    Kind Regards!
    Ping

    Hi Oliver,
    Thanks for the reply!
    I have login into the system, using User Id and Password.
    I have tried unsinstalling everything but the result remains the same.
    Previously only one service SAPCE_01 was showing up in the services explorer. But when I tried the
    Instance 00:
    sc create SAPRKT_00 binPath= "C:\usr\sap\RKT\SYS\exe\uc\NTI386\sapstartsrv.exe pf=C:/usr/sap/RKT/SYS/profile/CE1_SCS00_xxxxx" start= auto obj= "NT AUTHORITY\LocalService" password= abcd1234
    Instance 01:
    another service SAPCE1_00 was created. But when I tried to retry the instlattio, the installation again stopped at the point while starting the service and when I tried to retry it terminted with the following error.
    Please guide.
    sapinst.exe - Application Error
    The instruction at "0x00cbf040" referenced memory at "0x0072006d". The memory could not be "read".
    Click on OK to terminate the program
    Click on CANCEL to debug the program
    Selfextractor error
    iaextract.c:888: child has signaled an exec error. Keeping directory C:/DOCUME1/I047488/LOCALS1/Temp/sapinst_exe.1448.1196681060
    OK  
    Manish

  • Simple Date parsing Error

    Hello,
    I have used Simple Date extensively and have recently found what I think may be a bug.
    The API says that any string or character can be ignored in the input pattern by simply putting single quotes around it.
    If I have a date in raw format as follows: 2007-07-19T08:00:00
    I can use the input format yyyy-MM-dd'T'hh:mm:ss to parse this raw format above correctly. The single quotes around the T ignore this character in the parsing. This is fine.
    However, now I have a new raw format I have to deal with, it appears like this: 2007-07-19 08:00:00Z
    Now, SimpleDate handles the space just fine, however when I try to use this pattern, SimpleDate complains it cannot parse it.
    yyyy-MM-dd hh:mm:ss'Z'
    I have tried with many different characters and configurations but it seems there is a common bug here. If there is a character that is surrounded by single quotes at the END of the pattern, SimpleDate throws an exception.
    My question is should I be able to add ignored text in single quotes at any point in the pattern? Or are certain areas of the pattern off limits like the very end of the pattern?
    Thank you in advance for your response.
    TR

    jverd,
    Further research showed our app was running in J#. Run the command calls directly worked fine for each example. I am looking into how our app translates the text entered in the input field. Thank you for testing though.
    TR

  • Regarding simple date format

    Hi,
    Can any one please tell what is simple date format for below format.
    2008-11-04T11:49:04.312-04.00

    Basil wrote:
    I think all are getting confused with my question, I dont want to know how to convert date
    to a a particular format, I want to know if there is any format for 2008-11-04T11:49:04.312-04.00
    like yyyy-MM-dd'T'HH:mm:ss.SSS for 2008-11-04T11:49:04.312. My JDK version is 1.4
    Edited by: Basil on Nov 4, 2008 7:43 AM
    Edited by: Basil on Nov 4, 2008 7:43 AMRead the link for SimpleDateFormat and make one. How is that hard to understand? And it is what you have been being told from the beginning, and would have realised had you actually read the API docs pointed to. All the information you need to do so is there.

  • Issues in Simple Data Type - Float

    Hi SDN,
    I have created a simple data type of float and assigned to a context attribute. I have mentioned that  the minimum and maximum inclusive value for the float as 0.1 and 29.9. This is assigned to a field aaa. When the page loads for the first time, there appears 0 by default and if I dont edit the field and try saving, it doesnt throw any error message. It accepts the value which was very strange to me. But if I edit the value and put as 0.0, it throws error message saying, the acceptable value for the field is between 0.1 and 29.9.
    What should I do to resolve this issue? Also Can I make the field empty instead of a zero appearing the field?
    Regards,
    Ganesh N

    Hello Ganesh,
    Whatever the value you have provided only that values are allowed in that input field. if the value is 0 or 0.0 you can validate that attribute and throw an error message that "The Value should not be 0".
    Regards
    Nizamudeen SM

  • Problem with central build of Simple Date Type with Enumeration

    Dear gurus,
    I hope I'm posting this in the correct forum. Please advise if I'm in the wrong forum.
    I have a Web Dynpro DC in which I've created a simple data type with enumeration.  It is used for binding to a radio box. The data type is called DownloadType; the enumeration contains two vales: current and archive. To allow me to access the enumeration values, I turn on the "Generate a class representation of the enumeration" in the data type builder.
    I then reference the enumeration values with code like:
    if (downloadType.equals (DownloadType._CURRENT))
        yada yada yada
    This works fine when building locally and deploying directly. But when the DC is built by CBS (or doing a "Development Component->Build..." in NW Dev Studio), the build fails, stating that the DownloadType._CURRENT symbol cannot be resolved.
    For example:
    C:yadayadayada.java:227: cannot resolve symbol
    symbol  : variable _CURRENT
    location: class yadayadayada.DownloadType
                    equals(DownloadType._CURRENT))  {
    Apparently the central builder is not smart enough to handle the "Generate a class representation" flag.
    Is this a known problem? Are there any workarounds?
    Thanks in advance for any help you can provide.
    -Kelly
    P.S. Environment: 2004s

    Hi Kelly,
    works for me using SP10, what SP are you on?
    There's a line in the DC log that says:
         [ddgen] [Info]    Generating datatypes/com/x/x/x/MyEnum.java
    and the java compiler includes the matching path for compilation:
          [echo]   source paths:
          [echo]     ...\_comp\src\packages
          [echo]     ..\t\ABF37B5AFB3B2E8A76FFD29E7862EA48\gen_ddic\datatypes
    Regards,
    Marc

  • Simple Date Problem

    Hello,
    I'm stuck against a simple date query and need some help. Can anyone please shed some light on this?
    Our Environment is: oracle 8i and SYsdate format is: GMT.
    I have a table say employee with the following fields;
    Employee_id,employee_name,hire_date,is_new
    I have to find:
    Select employee_name
    From employee
    Where is_new = ‘Y’
    And hire_date between (00 GMT) and now.
    So, my problem is:
    How do I do the AND Clause?
    How can I get between 00GMT of today and now.
    Any help will greatly be appreciated. THanks in advance
    simak

    You could also use
    Select employee_name
    From employee
    Where is_new = ‘Y’
    And hire_date >= trunc(sysdate);

  • Help with simple date formatter

    hi i have a text box which has a date , day , time on it, i would like to use simple date formatter and change the format...
    i would like to get the day part alone getin displayed below the text box,
    any suggestions?

    Yes. Read the SimpleDateFormat API docs about specifying formatting patterns.

  • Simple data collector

    First off, its been years since I've written any code and that was 1st and 2nd year college programming classes with Visual Basic 6 (I still have the install CDs). So basically I remember only concepts of IF THEN ELSE, etc not the nuts and bolts of
    writing the code :)
    I am wanting to create a simple data collector for my photography business. I want the students to enter their names and emails into forms and the app to enter the info into an excel spreadsheet. When the student hits enter, the app prints a page with their
    name in large letters which I include in their first shot (so later I can put a face with a name)
    I have created a form that has the visual look of my desired app, I need help with the nuts and bolts...
    Thanks so much for any help...   Tom

    Tom,
    When I'm done with this I'll zip up the project folder and upload it for you (if you want me to). That will be easier that copy/paste.
    I have a start on it and a preliminary test so that you can see what I have here. I have namespace called "Student" and some classes in that namespace as shown on a
    page of my website here.
    The way that I have it set up, the parent's e-mail(s) is optional. If you want it to be mandatory I can make it that way, but you might want to re-think that - not all parents will have one. Anyway, the following shows my first test:
    Option Strict On
    Option Explicit On
    Option Infer Off
    Public Class Form1
    Private studentList As New List(Of Students.StudentData)
    Private Sub Form1_Load(sender As System.Object, _
    e As System.EventArgs) _
    Handles MyBase.Load
    ' Test it here
    Try
    Students.StudentData.AddNewStudent(studentList, _
    "Frank", _
    "Smith", _
    Students.StudentData.StudentLevel.Senior, _
    "[email protected]")
    ' Uncomment the following out and it will
    ' throw an exception about the e-mail being
    ' a duplicate:
    'Students.StudentData.AddNewStudent(studentList, _
    ' "John", _
    ' "Doe", _
    ' Students.StudentData.StudentLevel.Graduate, _
    ' "[email protected]")
    Students.StudentData.AddNewStudent(studentList, _
    "Mary", _
    "Jones", _
    Students.StudentData.StudentLevel.UnderGrad, _
    "[email protected]")
    Students.StudentData.AddNewStudent(studentList, _
    "Jim", _
    "Anderson", _
    Students.StudentData.StudentLevel.UnderGrad, _
    "[email protected]", New String() _
    {"[email protected]", _
    "[email protected]"})
    Students.StudentData.ExportToEncryptedXML(studentList)
    Students.StudentData.ImportFromEncryptedXML(studentList)
    Stop
    Catch ex As Exception
    MessageBox.Show(String.Format("An error occurred:{0}{0}{1}", _
    vbCrLf, ex.Message), _
    "Program Error", MessageBoxButtons.OK, _
    MessageBoxIcon.Warning)
    End Try
    End Sub
    End Class
    The XML file is saved into the program's Application Data folder which one of the classes automatically creates for you. Even if that were to be discovered, it wouldn't do anyone a lot of good.
    This is what they'd find based on the data entered as shown above in my test.
    Tell me your thoughts of this so far please?
    Still lost in code, just at a little higher level.

  • Simple data extraction reports by SAPu2019s SQL

    Hi,
    Can you please let me know how can I develop simple data extraction report using SAP's sql.
    Regards,
    Koushik

    HI,
    I have to do a PoC on Data Quality checks. In which there will be few reporting tables. One will be daily agreegate, one weely agreegate etc. Now I have to show those the data in form of reports. and Option is also required to drill down and drill up for those reports.
    Please let me know if I am able to clarify my question or not.
    Regards,
    Koushik

Maybe you are looking for

  • Byte array convert to image works fine for a peiod of time, Then error

    Hi all I'm on a program of reading incoming image set which comes as byte arrays through socket and convert them back to images using the method. javax.microedition.lcdui.Image.createImage();This works perfect for some time. But after 1 minute of run

  • How to delete a customize table

    HI, I need to delete a customize table . But while trying to delete the table it's showing a message " Still used in dictionary. can't delete'. because this table is used by some programs and search helps. How to delete the table? Thanks & regards sa

  • Why can't I create all day events on my phone in calendar anymore?

    I used to be able to create all day events in calendar on my iphone 3 but now I can only do this on the computer.

  • Delete key not working

    When I try to delete a letter in my text message it just types another letter "C Z", and when I hit enter it types a star? I've tried taking the battery out twice. Not sure what to do.

  • Lifedrive and Windows 7/64 bit

    I have a lifedrive and try to synchronize under Windows 7/64 bit with bluetooth. Do I have a chance with Palm Desktop 4.14 or 6.2? I remember, for the liefedrive, it is necessary to install another software, to get it compatible. But I did not find t