Convert string to a date

Gurus,
It would be highly appreciable if you could help me in knowing how to convert a string to date in obiee. I know we need to use CAST function. I don't have enough material to figure it out myself.
Awaiting a reply.
Thanks.

Nico - Thanks for the link, this is very helpful. Please tell me what's wrong in the following code. Am enlcosing the code and the error.
Code 1 :
CAST(CAST('31-OCT-'||CAST(YEAR("Dim - MBS Loan"."CLOSING DATE") AS CHAR) AS CHAR) AS DATE)
Error 1:
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 25137, message: ORA-25137: Data value out of range at OCI call OCIStmtExecute: select distinct D1.c1 as c1, D1.c2 as c2, D1.c3 as c3,
Code 2 :
CAST('31-OCT-'||SUBSTRING(CAST(YEAR("Dim - MBS Loan"."CLOSING DATE") AS CHAR),3,2) AS DATE)
Error 2:
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 1840, message: ORA-01840: input value not long enough for date format at OCI call OCIStmtExecute: select distinct D1.c1 as c1, D1.c2 as

Similar Messages

  • Converting string to util date

    I have a method to define if a string value can be converted into date.
    When I pass "20080815" value as a parameter it works fine. But when I pass "20082415" value it also converts the value to a date where the value should not be converted to date. At least I expect so. It should throw an exception because month can not be 24.
    Why an how could it be? And is there another way to solve the situation?
        public static int ToDate(String p_value) {
            try {
                DateFormat df = new SimpleDateFormat("yyyyMMdd");
                date_val = df.parse(p_value);
                return 1;
            catch(Exception e) {
                return -1;
        }Edited by: kalyon on Sep 4, 2008 3:50 AM
    Edited by: kalyon on Sep 4, 2008 3:50 AM

    df.setLenient(false);read the API docs.

  • Convert String to sql date

    hi all,
    i have a date in string format Tue, 06 Feb 2007 12:38:17 GMT
    How do i convert it to sql datetime.
    Date date = new Date("Tue, 06 Feb 2007 12:38:17 GMT");// creating date
              java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
                        "yyyy-MM-dd HH:mm:ss");// format definition
              java.sql.Time pubDate = java.sql.Time.valueOf(sdf.format(date));
              System.out.println(pubDate);This code gives me java.lang.NumberFormatException.
    Thanks in advance.......
    VikraM

    is "EEE d MMM yyyy HH:mm:ss Z" your default data format
    if not your first constructor will not parse date properly so your date object contains invalid date, when you try to format it it throws exception.
    check it
    sudhir nimavat

  • How to convert string value to date

    hi,
    in my application user enters the date in dd/MM/yyyy formatt..before submtiing to some external server i haveto formatt it to MM/dd/yyyy format bcos it accepts olny this formatt.when i retrieve the string date in my jsp using Sring date = req.getParameter();
    i want to convert this date to MM/dd/yyyyy formatt.
    Regards,

    Sring date = req.getParameter();
    string formatted = date.substring(0,3) + "/" + date.substring....
    ?

  • Convert string to fomated date

    I have a string type "dd/mm/yyyy", how can i convert it to "MMMddyyyy hh::mm:ss AM/PM" date format ??

    Calendar cal0 = Calendar.getInstance(); // today's date
                   SimpleDateFormat dateFormat = new SimpleDateFormat("MMMddyyyy hh::mm:ss AM/PM");          
                                                      cal0.add(Calendar.DATE,-0);
                                                      Calendar calx=cal0.getInstance();
              String date0 = dateFormat.format(cal0.getTime());
                                                                                                        System.out.println("Date "+date0);
    use this,.
    if there is any problem write it again,
    bye,
    Samir

  • Convert string to floating-point

    Hi all,
    ..very basic question, but I tryed it for hours and only received short-dumps
    <b>How can I convert a string into a floating-point number?</b>
    Kind regards,
    Stefan

    hi
    try this
    to convert  string to float.
    data : a type f,
    s type string value '1.023'.
    a = s.
    write :/ a.
    to convert float to string.
    data : a type f value '1.023',
    s type string.
    s = a.
    write : s.

  • Not able to convert string attribute to number and date please help me out

    not able to convert string attribute to number and date attribute. While using string to date conversion it shows result as failure.As I am reading from a text file. please help me out

    Hi,
    You need to provide an example value that's failing and the date formats in the reference data you're using. It's more than likely you don't have the correct format in your ref data.
    regards,
    Nick

  • Convert String to Date and Format the Date Expression in SSRS

    Hi,
    I have a parameter used to select a month and year  string that looks like:    jun-2013
    I can convert it to a date, but what I want to do is,  when a user selects a particular month-year  (let's say "jun-2013")
    I  populate one text box with the date the user selected , and (the challenge Im having is)  I want to populate a text box next to the first text box with the month-year  2 months ahead.    So if the user selects 
    jun-2013   textbox A will show  jun-2013 
    and textbox B will show  aug-2013..
    I have tried:
    =Format(Format(CDate(Parameters!month.Value  ),  
    "MM-YYYY"  )+ 2  )   -- But this gives an error
    This returns the month in number format   like "8"    for august...
    =Format(Format(CDate(Parameters!month.Value  ), 
    "MM"  )+ 2  )
    What is the proper syntax to give me the result    in this format =  "aug-2013"  ???
    Thanks in advance.
    MC
    M Collier

    You can convert a string that represents a date to a date object using the util.scand JavaScript method, and then format a date object to a string representation using the util.printd method. For more information, see:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1254.html
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1251.html
    In your case, the code would be something like:
    var sDate = "2013-01-10";
    // Convert string to date
    var oDate = util.scand("yyyy-mm-dd", sDate);
    // Convert date to new string
    var sDate2 = util.printd("mm/dd/yyyy", oDate);
    // Set a field value
    getField("date2").value = sDate2;
    The exact code you'd use depends on where you place the script and where you're getting the original date string, but this should get you started.

  • How to convert a string value to date

    Dear All,
    I am new to powershell script, i was trying to store a Ad user password set date to a variable add, add a number of days to get the expire date.
    but when i try to convert the variable to date value, I am getting the error as below.
    Please help me......
    PS C:\script> $passwordSetDate = (get-aduser user1 -properties * | select PasswordLastSet)
    PS C:\script> $passwordSetDate
    PasswordLastSet
    7/15/2014 8:17:24 PM
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    Cannot find an overload for "ParseExact" and the argument count: "3".
    At line:1 char:1
    + $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodException
        + FullyQualifiedErrorId : MethodCountCouldNotFindBest
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)

    Dear All,
    I am new to powershell script, i was trying to store a Ad user password set date to a variable add, add a number of days to get the expire date.
    but when i try to convert the variable to date value, I am getting the error as below.
    Please help me......
    PS C:\script> $passwordSetDate = (get-aduser user1 -properties * | select PasswordLastSet)
    PS C:\script> $passwordSetDate
    PasswordLastSet
    7/15/2014 8:17:24 PM
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    Cannot find an overload for "ParseExact" and the argument count: "3".
    At line:1 char:1
    + $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodException
        + FullyQualifiedErrorId : MethodCountCouldNotFindBest
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    In your post you ask how to convert a string value to a date.  The value returned from the Get-AdUser is already a date.  It does not need to be converted.
    Bill has sshown one way to convert a date to a string and there are other methods.  You need to clarify your question.
    If you are really trying ot convert strings to dates then you can start with this:
    [datetime]'01/21/1965 13:33:23'
    Most date strings aer autodetected by the class.
    ¯\_(ツ)_/¯

  • How to convert String (dd-MMM-yyyy) to oracle.jbo.domain.Date

    Hi
    Could you please tell how do I convert String of date in format dd-MM-yyyy to ADF date? Please show me some sample.
    Thanks

    http://javaalmanac.com/egs/java.text/FormatDateDef.html
    Once you have a java.util.Date you can convert it to oracle.jbo.domain.Date. (see http://www.fifkredit.com/bc4jdoc/rt/oracle/jbo/domain/Date.html)

  • How to convert string yyyy-mm-dd to date dd/mm/yyyy

    Hi Experts,
    I am getting date in the form of string 2007-06-30 from R/3. How I can convert this string into a date in the form 30/06/2007. I have to use java.sql.Date.
    Following code is not working. As for executing the following code, I have to use java.util.date. I can not use java.util.date as the Web Dynpro program uses java.sql.Date.
         SimpleDateFormat sdf1 = new SimpleDateFormat("dd/mm/yyyy");
         Date d = null;
         d = sdf1.parse(wdContext.currentContextElement().getDateClicked());
    Regards,
    Gary

    Hi,
    If I understood you right you need this date typed as a java.sql.Date?
    String ds=wdContext.currentContextElement().getDateClicked();
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");     
    java.sql.Date sd = new java.sql.Date(sdf.parse(ds).getTime());
    Four remarks:
    We "transport" the Date from java.util.Date to java.sql.Date as milliseconds since January 1, 1970, 00:00:00 GMT. See contract of java.sql.Date.
    You used dd/mm/yyyy instead of dd/MM/yyyy, but mm are the minutes and not the months, see the contract of [SimpleDateFormat|http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html] (JSE 1.4) .
    You do not set the time zone for DateFormat, so you use TimeZone.getDefault(). This is your JVM's default time zone and depends (if you did not change it) on your systems time zone. F.e. I live in Germany, the time zone of my system is currently MEZ (which is UTC+1) since we left the daylight saving time zone last sunday. Since you only parse the date and not the time zone f.e., you expect the date (the string) to be in your default time zone. If this is not the case, you have to set the time zone to the time zone you expect the date to be in (f.e. sdf1.setTimeZone(TimeZone.getTimeZone("UTC"));) before parsing the date. This might seem marginal in your case, but may produce unexpected results with date comparisons and date parsings around the day change.
    SimpleDateFormat is not thread-safe, so please do not cache it! This is not mentioned in the Javadoc of JSE 1.4, but can be looked up at [Sun's bug database|http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=96669461418011fffffffffb70dd6b6e88eb5?bug_id=4264153]. If you are not satisfied with the standard Date & Time handling (f.e. performance reasons) you might want to consider an alternative like [Joda Time|http://joda-time.sourceforge.net/index.html] which is published under [ASF 2.0 license|http://joda-time.sourceforge.net/license.html]
    Best regards,
    Fabian

  • Need info on SimpleDateFormat, Converting String to Date

    I'm a newbie and doing a conversion of a string to a date and it's adding a little less than 11 minutes. I know I'm missing something really simple but as I read it I ought to be able to convert "20030125 084539.637696" to Sat Jan 25 08:45:39 not 8:56! Also, for the time being I'm ignoring the zulu 'Z' because I can't find a pattern that'll take it.
    System.out.println("INFO:MetadataExtractorBean::filestarttime:" + filestarttime);
    filestarttime = filestarttime.replace("Z","");
    System.out.println("after filestarttime.replace(Z,null) filestarttime:" + filestarttime);
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd hhmmss.SSSSSS");
    Date convertedDate = dateFormat.parse(filestarttime);
    System.out.println("after dateFormat.parse(filestarttime) convertedDate:" + convertedDate);
    INFO:MetadataExtractorBean::filestarttime:20030125 084539.637696Z
    after filestarttime.replace(Z,null) filestarttime:20030125 084539.637696
    after dateFormat.parse(filestarttime) convertedDate:Sat Jan 25 08:56:16 EST 2003
    Can someone help me with a) why it doesn't remain 8:45, and b) how to modify the pattern to be able to parse a zulu date. Thanks in advance.

    import java.text.*;
    public class ParsingExample {
        public static void main(String[] args) throws ParseException {
            String s = "20030125 084539.637";
            SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd HHmmss.SSS");
            System.out.println(f.parse(s));
    }Your round up was because ".637696" was taken to mean 637,696 milliseconds. SimpleDateFormat doesn't have a way to accept microseconds, and anyway, java.util.Date only has millisecond precision. I also changed "hh" to "HH" because I assume this is with a 24 hour clock.
    edit: you can tell your date format not to do these roll ups by setting:
    f.setLenient(false);

  • Error in converting character string to smalldatetime data type

    I've installed SQL Server 2000 on my new laptop and Crystal Report XI, out of sudden, the Crystal Report to certain view can't run and I got the following error:
    Details: 22007 [Microsoft][ODBC SQL Server Driver][SQL SERVER]Syntax Error cnverting character string to smalldatetime data type.
    Any suggestions?
    Hannah

    Here is the view the err is complaining about:
    SELECT     TOP 100 PERCENT Cur.Closed_Month, Cur.Closed_Year, Cur.Incidents_Closed, Prev.Incidents_Closed AS PrevIncidents_Closed,
                          YrAgo.Incidents_Closed AS YearIncidents_Closed
    FROM         (SELECT     Closed_Month, Closed_Year, Incidents_Closed
                           FROM          dbo.Incidents_Closed) Cur INNER JOIN
                              (SELECT     Month(CONVERT(datetime, CAST(closed_month AS varchar) + '/01/' + CAST(closed_year AS varchar), 101) + 32) AS PrevMonth,
                                                       year(CONVERT(datetime, CAST(closed_month AS varchar) + '/01/' + CAST(closed_year AS varchar), 101) + 32) AS PrevYear,
                                                       Incidents_Closed
                                FROM          dbo.Incidents_Closed) Prev ON Cur.Closed_Month = Prev.PrevMonth AND Cur.Closed_Year = Prev.PrevYear INNER JOIN
                              (SELECT     Month(CONVERT(smalldatetime, CAST(closed_month AS varchar) + '/01/' + CAST(closed_year AS varchar), 101) + 366) AS PrevMonth,
                                                       year(CONVERT(smalldatetime, CAST(closed_month AS varchar) + '/01/' + CAST(closed_year AS varchar), 101) + 366) AS PrevYear,
                                                       Incidents_Closed
                                FROM          dbo.Incidents_Closed) YrAgo ON Cur.Closed_Month = YrAgo.PrevMonth AND Cur.Closed_Year = YrAgo.PrevYear
    What confused me is that it works fine with my previous laptop. I wonder if there is any patch in Crystal Report or SQL server that used to support certain functions but not support them anymore....
    Thanks
    Hannah

  • Facing problem in converting string to date using getOANLSServices()

    I am trying to set a value for date field in my vo and trying to insert into the table.
    In controller I am getting the String which has a date:
    ex: String date="01-NOV-2007";
    while setting into the row I need to convert into Date but it is returning null.
    The below code I used
    to convert into date :
    Date dt = new Date(getOADBTransaction().getOANLSServices().stringToDate(date));
    But this dt is returning a null value is there any solution please advise me.
    Regards!
    Smarajeet

    Smarajeet ,
    See this thread, in one of my replies i have mentioned how to convert string to java.sql.date.You can use the same for oracle.jbo.domain.Date.
    urgent!How to set the default selected date for an OAMessageDateFieldBean
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Converting part of the string to a date and subtract with sysdate.

    HINT! In order solve this you must know how the pnr is assembled. Study this:
    650323-5510, we only need the first six characters. They inform us about when the person (car owner) was born. In this case it is 23 Mars 1965. You have to use several oracle built-in-functions to solve this. Hint! Begin by converting part of the string to a date and subtract with sysdate.
    select to_char(to_date(cast(pnr,'YYMMDDMM'))) from car_owner;
    please what am i doing wrong. i need the result to be something like this
    Hans, Rosenboll, 59,6 years.

    Hi.
    The main problem here is you have only last two digits of year. That could be the problem in a couple of years from now, when somebody born after 2k would get in to your database. For now if we ignore this problem the right solution would be :
    <code>
    SELECT months_between(trunc(SYSDATE),
    to_date('19' || substr('650323-5510',
    1,
    6),
    'YYYYMMDD')) / 12 years_old
    FROM dual
    </code>
    Suppose you are expecting the age of the car owner as a result above code will give you that. One again notice the '19' I appended.
    Best regards.

Maybe you are looking for