Conversion from string to date

hi,
Can someone tell me how can i convert a string "09/09/02" to date ......

HaHaHa jboeing is Sooo instructional. Yes, please to read instructions, bang head for four hours and then do this -import java.util.*;
import java.text.*;
public class DateTest
   public static void main(String[] args)
      String dateStr = "09/09/02";
      Date date = new Date();
      SimpleDateFormat sDF = new SimpleDateFormat("MM/dd/yy");
      try{
         date = sDF.parse(dateStr, new ParsePosition(0));
      }catch(NullPointerException npe)
      {System.out.println("bad parse");}
      java.sql.Date sqlDate = new java.sql.Date(date.getTime());
      System.out.println(date.toString());
      System.out.println(sqlDate.toString());
}

Similar Messages

  • Conversion from string to Date Query.

    Hi,
    I need a way to convert a date format which is in string to a date data type.
    String is in the following format : Tue Feb 27 16:00:31 PST 2007
    Have used the SimpleDateFormat class but it returns an unparseble data error.
    Any thoughts????
    Regards
    Sam W

    Please don't crosspost: http://forum.java.sun.com/thread.jspa?threadID=5142482

  • Conversion from string "20041023 " to type 'Date' is not valid.

    Hi ,
       I have a table with one of the column(EmpHiredate) datatype is char(10). It has value like "20141023". I need to display this value as date format(dd/mm/yyyy) in report. 
    Following methods i tried in textbox expression but no luck.
    =Format(Fields!EmpHireDate.Value,"dd/MM/yyyy")
    =Cdate(Fields!EmpHireDate.Value)
    Error:
    [rsRuntimeErrorInExpression] The Value expression for the textrun ‘EmpHireDate.Paragraphs[0].TextRuns[0]’ contains an error: Conversion from string "20041023  " to type 'Date' is not valid.
    Is it possible to convert string to date using SSRS textbox expression ? Can anyone help me with the solution.
    Thanks,
    Kittu

    Hi Jmcmullen,
         Found one more issue on the same. I have one value like "00000000" for the column(EmpHiredate)
    , when i use above expression values(ex:"20141023")
    are displaying in dd/MM/yyyy format in report except value like "00000000" and giving following error:
    [rsRuntimeErrorInExpression] The Value expression for the textrun ‘EmpHireDate.Paragraphs[0].TextRuns[0]’ contains an error: Conversion from string "0000/00/00" to type 'Date' is not valid.
    Even i tried to pass its original value("00000000") as below but no luck.
    =IIF(Fields!EmpHireDate.Value = "00000000","00000000",Format(CDATE(MID(Fields!EmpHireDate.Value,1,4) + "/" + MID(Fields!EmpHireDate.Value,5,2) + "/" + MID(Fields!EmpHireDate.Value,7,2)),"dd/MM/yyyy"))
    Also tried this:
    =IIF(Fields!EmpHireDate.Value = "00000000","2000/10/21",Format(CDATE(MID(Fields!EmpHireDate.Value,1,4) + "/" + MID(Fields!EmpHireDate.Value,5,2) + "/" + MID(Fields!EmpHireDate.Value,7,2)),"dd/MM/yyyy"))
    Please Suggest. 
    Thanks ,
    Kittu

  • Conversion from string "" to type 'Double' is not valid

    We're using BPC 7.5 MS and on patch level 111.02
    There's two front-end servers and one back-end.  we have about 100 users but concurrency is likely in the 50 range.
    We've been running extremely well for about 4 years but are now starting to run into problems.
    There are about 5-6 applications but none greater than 10 million records.  We optimize regularly.
    However over the past two months admin processes seem to take a lot longer.  Optimization now times out after about 1.25 hours and none used to take greater than 15 minutes.
    Today after processing dimensions we checked the application status and we were not able to check if it was available or not.  We got a pop up box saying
    conversion from string "" to type 'Double' is not valid
    I've processed dimensions and applications since and still this error persists.
    We're attempting a reboot to see if that helps but I've never seen this before and in combination with the slower admin processing I'm wondering if there's something drastic going to happen.
    Michael

    Hi Michael,
    for the poor performances you have to check the guides about performance on bpc if you have scheduled regurarly optimize during day and night (just verify that never factwb reach 50.000 and fac2 500.000 records) maybe you need to change some parameter on the server as MaxThreads.
    For the conversion string error on admin console see please this note 1803092 - Set application set status error
    Regards
         Roberto

  • Deprecated conversion from string constant to 'char*'

    Hi all
    I am working with strings and i cant figure out why the following
    warning appears at time of build.
    warning: deprecated conversion from string constant to 'char*'
    It appears for the line
    char *myName = "Apple.txt";
    Is there anyone who can help me?
    Help is welcome.
    Thanks in advance.

    Any reason why you aren't using NSString in place of char?
    char *myName = "Apple.txt";
    NSString *myName = @"Apple.txt";

  • Regarding conversion of String to Date

    Hi
    Ravi here and I am getting the following exception when i am working with String to date conversion.As i am working in LAN this code is working for all others .This problem is with my system only.This is not supporting with yyyy-MM-dd format.One more thing in my system only we installed VisualStudio.Is that a problem for this exception.I am using Myeclipse
    Plzzzzzzzzzzz help me I got strucked .
    Thanks in advance
    Code:
    public void testSaveDates() throws HibernateException, ParseException{
    try{
    Date date=new Date();
    String str1 ="2006-05-06";
    Date dateFormatter = new SimpleDateFormat("yyyy'-'MM'-'dd").parse(str1);;
    System.out.println(dateFormatter);
    catch(Exception e){
    e.printStackTrace();
    Exception:
    java.text.ParseException: Unparseable date: "2006-05-06"
         at java.text.DateFormat.parse(DateFormat.java:335)
         at chaitanya.MyTest.testSaveDates(MyTest.java:282)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at junit.framework.TestCase.runTest(TestCase.java:154)
         at junit.framework.TestCase.runBare(TestCase.java:127)
         at junit.framework.TestResult$1.protect(TestResult.java:106)
         at junit.framework.TestResult.runProtected(TestResult.java:124)
         at junit.framework.TestResult.run(TestResult.java:109)
         at junit.framework.TestCase.run(TestCase.java:118)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)

    Date date=new Date();You don't need this line.
    Date dateFormatter = new
    er = new
    SimpleDateFormat("yyyy'-'MM'-'dd").parse(str1);;As already told, you don't need the single quotes. And you don't need two semi-colons - that's unnecessary.
    I just wrote a sample code to test that out. Check it and see for yourself.
    import java.text.SimpleDateFormat;
    public class Test {
         public static void main(String[] args) throws Exception {
              System.out.println(new SimpleDateFormat("yyyy-MM-dd").parse("2005-04-18"));
              System.out.println(new SimpleDateFormat("'yyyy'-'MM'-'dd'").parse("2005-04-18"));
    }Output:
    Mon Apr 18 00:00:00 EDT 2005
    Exception in thread "main" java.text.ParseException: Unparseable date: "2005-04-18"
            at java.text.DateFormat.parse(DateFormat.java:335)
            at Test.main(Test.java:6)I wonder why it is not feasible to write a quick sample code.

  • Conversion from milliseconds to Date in 1.5

    A java.util.Date object can be constructed by passing the number of milliseconds since 1 January 1970 as a constructor argument. This Date can then be formatted to a human-readable format with SimpleDateFormat.
    I have tested this conversion from milliseconds to a date both in Java SDK 1.4.1 and Java 1.5.0 to see if there are differences in the way dates are calculated from milliseconds. It seems that there are differences when the system timezone is set to Europe/Berlin. The dates from 1.5.0 are one hour ahead of those from 1.4.1 in a certain week in May 1945 and a day in September 1945.
    This means that milliseconds that are generated from a date by using the Java 1.4.1 runtime and then stored are interpreted differently when they are retrieved when using java runtime 1.5.0, if they happen to be one of those days in 1945. This could cause discrepancies when an application is migrated to JDK 1.5.0.
    This is only a minor problem, but is there any way to know what caused these changes in SDK 1.5.0 and what these changes are? Is there historical data that the Sun implementation is based on to calculate dates from millisecond values?
    Any help is appreciated.
    Kind regards

    I found the following at "http://thedailywtf.com/forums/70146/ShowPost.aspx"
    In summer 1945, Berlin and the Soviet-occupied part of Germany observed a daylight savings time of two hours. Unfortunately, Sun's JRE 1.4 implementation of GregorianCalendar defines a maximum DST of one hour and, in non-lenient mode, rejects the 2 hours as invalid when recalculating all fields after the millisecond field is set.
    Here's the bug report: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4639407

  • Conversion of string into date????????????

    Can anyone tell how to convert a String into date??
    if the string is in the format "Thu Mar 25 17:11:34 GMT+05:30 2004"
    i have converted it. code is
    SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM d yyyy HH:mm:ss");
         dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));
    Date date = null;
    try
              //date = dateFormat.parse(new Date().toString());
              date = dateFormat.parse(dateLine);
         catch(ParseException ex)
    but i am not able to specify the year.
    so when i getYear on the new Date it return 1970.

    @duffymo, I'm pretty sure "d" is good for a two digit date, "dd" gives you zero-padding.
    The problem, presumably, is that the format string "EEE MMM d yyyy HH:mm:ss" does not match the actual format "Thu Mar 25 17:11:34 GMT+05:30 2004".
    The correct format string would be "EEE MMM d HH:mm:ss z yyyy"

  • Conversion of string to data(Flat file to sql server) Transformations

    Hi All,
    I have a requirement in which I am trying to convert a field of type string which contains date from source file to field of type datetime in sqlserver by using all the below expressions
    to_date(DATE, 'yyyy/mm/dd-hh24:mi:ss' )
    to_date(DATE, 'yyyy/mm/dd' )
    However it is not throwing any errors but the data of the date field is being loaded with null values(Date is present in flat file).
    Any inputs plz???
    Thanks
    U

    Can you post a sample of the date string you are trying to convert?

  • Convert from String to Date for storing in SQL Server 2000

    Hi,
    I've accepted some values from a user using a form in HTML.Now using Servlets I transfer the value to my java code .
    I want to know how can I convert a DATE accepted from the user thats presently in "String" format to the "datetime" format for SQL Server2000.
    Please guide me with some steps and I shall be grateful.
    Thanks

    The java.text.SImpleDateFormat class is most probably of use.
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    String enteredDate = "25/12/2006";
    java.util.Date utilDate = sdf.parse(enteredDate);
    java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());You can then use the java.sql.Date with the "setDate()" method of a prepared statement. This method would be database independant, as you are setting an actual date, not depending on a specific format on the database end.

  • Conversion from char to date

    I have a filename as final_20120928_142334.txt
    I have to get only date value from this as 20120928_142334
    then I have to convert this into date time format as yyyymmdd hh24:mi:ss

    To extract the actual filename into a table, use the code for the 'Retrieve File List' example in this document - on page 8.
    http://s3.amazonaws.com/Ora/ODI_Waiting_for_a_file_and_processing_it.pdf
    Then use the expression posted by 955950 above to format the string.
    Edited by: _Phil on Sep 28, 2012 11:48 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Conversion of String to date

    Hello,
    I have a date in String format like "01/03/2006"
    How can I get "Mar-2006" in java?
    Please Help

    have a look at that:
    http://www.javaworld.com/jw-12-2000/jw-1229-dates.html
    regards.

  • Converstion from String to Date

    Hi,
    I need a way to convert a date format which is in string to a date data type.
    String is in the following format : Tue Feb 27 16:00:31 PST 2007
    Have used the SimpleDateFormat class but it returns an unparseble data error.
    Any thoughts????
    Regards
    Sam W

    It's my first and second thought.
    The original poster never showed us the code that didn't work for him.
    It would have taken a whole two lines. When will people learn that
    the best way to get help is to post a short example program demonstrating
    their problem? I mean, it's not rocket science. Isn't it obvious that, instead
    of writing "my code doesn't work, I get this error and oh by the way, I'm
    not actually going to show you the format string that doesn't work" they could
    just post the durn code. But no, that would make too much sense.

  • Parsing from string to date object

    How can I convert a time in String format to a Date object?
    ie. 14:30:05(String) to 14:30:05

    How about this?
    String sDate = "14:30:05";
    StringTokenizer tokenizer = new StringTokenizer(sDate, ":");
    Calendar calendar = new Calendar();
    int hour = Integer.parseInt(tokenizer.nextToken());
    int minute = Integer.parseInt(tokenizer.nextToken());
    int second = Integer.parseInt(tokenizer.nextToken());
    calendar.set(Calendar.HOUR_OF_DAY, int hour);
    calendar.set(Calendar.MINUTE, int minute);
    calendar.set(Calendar.SECOND, int second);
    Date dDate = calendar.getTime();I didn't try it, but it should be pretty close (unless you want to use deprecated methods, then it can be shorter...)

  • Conversion from timestamp to date

    Hi All,
    Does anyone know how to convert a timestamp value to a date???
    Any help is appreciated

    I want to send the value as a date. This is because
    in other .java file i accept this value as
    java.sql.Date as a parameterWhy do you have java.sql.Timestamp objects then?
    Why not directly getting java.sql.Date object from database?
    Why do your java classes use java.sql.Date instead of java.util.Date?

Maybe you are looking for

  • In adf,how to delete a file generated on server,when the webpage is closed

    Hi, I have an application consisting of 2 pages. in the 1st page i will give some input details and when i click on submit, some java code is getting executed in the back. That java code generates a csv file in the server location. after succesful ex

  • Importing photos from DVD

    I am new to Mac's and to iPhoto. I have had some success importing photos that I backed up to DVD using my PC but one DVD is causing me problems. I can view the JPEG photos stored on the DVD when I use my PC but for some reason my Mac can only see th

  • Cannot select tracks on ipod classics through Itunes.

    Hi Once I connect my new IPOD to my mac, the IPOD itself shows up and the list of music on the IPOD shows up in ITunes, but I edit/select tracks at all. Its as if they are locked. Any idea how to overcome this?

  • Change display Date format from 06.2011 to june 2011 in output of Query

    Hi All,             Change display Date format from 06.2011 to june 2011 in output of Query  Execution. i used time charcteristics 0calmonth in query, output display is coming 06.2011, i want to display output in june 2011 format, anyone tell me how

  • Word searchable filetypes

    I need to take Acrobat 9 Pro PDF files and export or save the pages as a filetype that when inserted into MS Word 2010, it is word searchable. Usually I save image files as .emf's because they are searchable in Word. Does anyone know if another filet