How to read date as string (format dd-mm-yyyy) and store it as Date object

Hi. I would like to read from keyboard String with a date and put this value to Date object. How can i do this???
Thanks

Check out java.text.SimpleDateFormat.
Basically
String dateString = readUserInput(); // get the string
SimpleDateFormat myFormat = new SimpleDateFormat("dd-MM-yyyy");
Date myDate = myFormat.parse(dateString);

Similar Messages

  • How to convert BLOB data into string format.

    Hi,
    I have problem while converting blob data into string format.
    for example,
    Select dbms_lob.substr(c.shape.Get_wkb(),4000,1) from geotable c
    will get me the first 4000 byte of BLOB .
    When i using SQL as i did above,the max length is 4000, but i can get 32K using plsql as below:
    declare
    my_var CLOB;
    BEGIN
    for x in (Select X from T)
    loop
    my_var:=dbms_lob.substr(x.X,32767,1)
    end loop
    return my_var;
    I comfortably convert 32k BLOB field to string.
    My problem is how to convert blob to varchar having size more than 32K.
    Please help me to resolve this,
    Thanx in advance for the support,
    Nilesh

    Nilesh,
    . . . .The result of get_wkb() will not be human readable (all values are encoded into some binary format).
    SELECT utl_raw.cast_to_varchar2(tbl.geometry.get_wkt()) from FeatureTable tbl;
    -- resulting string:
        ☺AW(⌂özßHAA
    Å\(÷. . . .You may also want to have a look at { dbms_lob | http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_lob.htm#i1015792 } "The DBMS_LOB package provides subprograms to operate on BLOBs, CLOBs, NCLOBs, BFILEs, and temporary LOBs."
    Regards,
    Noel

  • Convert a date in String format to a Date

    Hi,
    How can I convert a date in String format to a Date object?
    I have tried:
    import java.text.*;
    import java.io.*;
    import java.util.Date;
    import java.util.Locale;
    import java.sql.*;
    public class casa {
    public static Connection con = null;
    public static Statement s = null;
    public static String sql = null;
    public static String mydate = "01.01.2001";
    /** Creates a new instance of casa */
    public casa() {
    public static void main(String[] args) throws SQLException{
    try {
    DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT);
    Date date = shortFormat.parse(mydate);
    //Open Database
    con = getConnection();
    s = con.createStatement();
    sql = "select date1 from table1 where date1 <= '"+date+"'";
    ResultSet rs = s.executeQuery(sql);
    while(rs.next()){
    String aba = rs.getString("datum");
    System.out.println("New Datum = "+aba);
    } catch (Exception ex ) {
    ex.printStackTrace();
    closeConnection(s, con);
    //Connection
    private static Connection getConnection() {
    Connection con = null;
    String user ="aouzi";
    String passe ="aouzi";
    String url = "jdbc:db2:EjbTest";
    try {
    //Datenbanktreiber laden
    Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
    //Verbindung herstellen
    con = DriverManager.getConnection(url,user,passe);
    }catch(ClassNotFoundException e){
    } catch(SQLException e){}
    return con;
    //close Connection
    private static void closeConnection(Statement s, Connection con) {
    try {
    s.close();
    } catch (SQLException e) {}
    try {
    con.close();
    } catch (SQLException e) {}
    I'm getting the following errors:
    COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0180N
    The syntax of the representation of a date/time of day value as character sequence is false. .SQLSTATE=22007

    I'm pretty sure it won't understand what date.toString() returns. If you know what format the database understands, you do it like this:
    SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy"); // e.g. 18-Apr-02
    String datestring = sdf.parse(date);
    and use that instead of date in your sql string. Some databases understands it if you do
    "to_date('18-Apr-02')"
    so you could include that in your sql string as well..
    You could also try to make it a java.sql.Date and hope your jdbc driver knows how to convert it to a string that the database understands if you don't know the format:
    con = getConnection();
    PreparedStatement ps = con.prepareStatement("select date1 from table1 where date1 <= ?");
    ps.setDate(new java.sql.Date(date.getTime()));
    ResultSet rs = s.executeQuery(sql);

  • How to convert a date field with format (dd,mm,yyyy) to format (mm,dd,yyyy)

    Hello.
    How to convert a date field with format (dd,mm,yyyy) to format (mm,dd,yyyy)
    I have text field which has a databind to a date field. When I click on it, we can select the date, it is added on the format (dd,mm,yyyy). When I want to insert this date field to a database It doesnu2019t allow me to do it because it will only accept date field on the format (mm,dd,yyyy)
    I tried to store this format on a date variable and I get a message saying that is impossible to convert a string into a date.
    Regards,
    Jose

    Hi Jose,
    usually you format strings in c# like
    string.Format("{0:yyyyMMdd}", insertyourstring);
    in your case
    string.Format("{0:MM/dd/yyyy}", insertyourstring);
    [look here|http://idunno.org/archive/2004/14/01/122.aspx]
    there are more details
    if everything fails split the string with Mid()
    or ask me
    lg David

  • How test the date formats  M/d/yyyy and MM/dd/yyyy .

    how test the date formats M/d/yyyy and MM/dd/yyyy .format should accept 3/3/1982 and 03/03/1982 dates.
    please help me

    georgemc wrote:
    kajbj wrote:
    Spoiler: Reply #3 is actually the answer to your question.Also, Bruce Willis is a ghost, the Titanic sinks and Verbal is Keyzer Soze.Only one of those endings really surprised me.
    You should've heard me in that theatre when the Titanic struck that iceberg...

  • How to convert sysdate to the format dd-mon-yyyy

    how to convert sysdate to the format dd-mon-yyyy

    <how to convert sysdate to the format dd-mon-yyyy>
    This question is better answered by thinking about about how Oracle dates work. SYSDATE is a pseudocolumn (function without any arguments) that returns a date value: it already is a date. Oracle date values are stored not as we see them, say 'DD-MON-YY', but as a series of bytes with the different date components from the millennium down to the second. We NEVER see dates as they are stored but use the formats for automatic conversion.
    To display a date the way you want use TO_CHAR() with an edit mask or as others suggested change your NLS_DATE_FORMAT (thought I advise against this as most systems use DD-MON-YY and porting queries from other systems or even OTN can easily break). To change a converted string back to a date use TO_DATE() with an edit mask.

  • Validating a text field that has date in the format mm/dd/yyyy

    How can I validate a text field such that it should be in the format mm/dd/yyyy and it should not be greater that a particular date.
    for example the date I enter should not be greater than 01/01/2007

    What you can do is use the SimpleDateFormat class to try and parse the text date into a Date object like this:
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    Date mydate = sdf.parse(textdate);if that fails than the date has the wrong format (you'll get a ParseException if I'm not mistaken).
    The next step is to create a Date for 1/1/2007 and then do a date compare between your two dates. You can create a date yourself using the Calendar class.

  • Converting Date Column to format MM/DD/YYYY in RPD

    Hi all,
    I have a requirement like converting a Date column to format MM/DD/YYYY in RPD. Any help as we are not supposed to use the BI Answers Data Fomat for showing this format.
    Thankyou,
    Edited by: [email protected] on May 10, 2010 11:49 PM

    Hi Saichand,
    I need the resulting column in DATE format only. The solution which you specified converts the datatype to character. Is there anyway to convert the format but not the datatype.

  • HT1386 I am having problem syncing my itunes data from my computer to my ipod and ipad. My data is not fully transferred.  Can someone help me?

    I am having problems syncing my itunes data from my computer to my ipod and ipad.  The data from my computer is not transferring.  Can someone help me?

    What happens when you try to sync?
    Does any media sync?
    Was the iPod previous synced to another iTunes library/computer?
    Have you successfully synced from this iTunes library/computer before?
    Do the songs play in iTunes?
    Do you have the right boxes checked to sync?
    iTunes: Syncing media content to iOS devices and iPod        

  • Date Problem-adding 30days to the date in string format.

    hi i have an Date in the form of String "yyyy-mm-dd",i have to add 30 days to that date and compare it with to days date,i try to convert the string in to date format using SimpleDateFormat,but i could not understand how to add 30 days to that.pl it's an urgent problem,any help would be appreciated.
    Regards.

    to compare the date to todays date,
    Calendar todaysDate = Calendar.getInstance();
    todaysDate.after(cal2);
    todaysDate.before(cal2);
    Depending on which way you want to know.
    To get the String Format I would suggest something like :
    String dateInString = "" + cal2.get(Calendar.YEAR) + "-" + cal2.get(Calendar.MONTH) + "-" + cal2.get(Calendar.DATE);
    Be careful though as this may give a format YYYY-M-D if the month or date is a single digit, so you may have to test string.length and then have "0"+cal2.get(Calendar.MONTH) /cal2.get(Calendar.DATE)
    Hope this is of some help.

  • How to read/convert hexidecimal string to an interger

    Hello everyone,
    This is probably very simple but non of my books show what I need to do. I am running Java 1.4.2 and not ready yet for 1.5.
    I wanted to read Property entries containing hexidecimal entries and then convert the hexidecimal entries (which are in String format) into a number either int., long,double or Interger.
    Property entry:
    address=0x06FE
    Property prop = new ....
    String addr = prop.getProperty("address");
    Interger num = new Interger.parseInt(addr); <---- fails
    Would appreciate your help
    Regards,
    Ulises

    Integer.parseInt(addr, 16);
    //or
    Integer.valueOf(addr, 16);
    Note that you should call the method by the classname, as it's static. Do n't try to do new Integer as you're doing.

  • I can't sync/back up iPhone data to my computer b/c iPhone screen is shattered and i cant unlock it to enter in my passcode. How can I sync my broken iPhone with my computer and back up my data so I can sync and transfer the data to my replacement iPhone?

    I can't sync my iPhone and back up my data with my computer because iTunes says to enter the passcode into my iPhone to unlock it, but I am unable to unlock and enter in my passcode on my iPhone because the screen is shattered. I have my replacement iPhone with me and I'm not going to activate it until I can sync/get the data from my broken iPhone. I have the envelope to send my broken iPhone back to the Verizon store or whatever so that's not a problem. I just can't sync my old iPhone with my computer.
    Thanks.

    No I haven't synced my iPhone with the computer I'm currently using. The computer that I normally sync my iPhone with is being repaired.
    I read a nearly identical question to mine (in which you answered) and I found my the answer. Thanks!
    Now I have a few more questions: If I mail my broken iPhone to Asurion, will I be able to get my data off of my iPhone once Asurion has it? And what will happen to my old iPhone and the data on it if I activate my replacement iPhone? Will my broken iPhone just become de-activated and will the data be erased or lost or something? Could I still sync it (with the computer ir originally synced with) and back up the data?
    Thanks.

  • How can i convert if the date in string format

    String lFstr = (String) pReq.getParameter("FND");
    String lTstr = (String) pReq.getParameter("TND");
    String lLstr = (String) pReq.getParameter("LWD");
    System.out.println(lFstr + " " + lTstr + " " + lLstr);
    //DateFormat ds = DateFormat.getDateInstance();
    DateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
    Date lFdate = null;
    Date lTdate = null;
    Date lLdate = null;
    try {
    lFdate = dateFormatter.parse(lFstr);
    lTdate = dateFormatter.parse(lTstr);
    lLdate = dateFormatter.parse(lLstr);
    } catch (Exception e) {
    System.out.println(lFdate+" "+lTdate+" "+lLdate);
    i am getting the values from request parameters at that time it is giving values.
    after convertion of string to date it is giving the null value what is wrong in this code

    It might have thrown an exception. Try printing the stack trace in the catch block.

  • How to read in text string pairs from an external txt file?

    I have an external txt file containing 26000 pairs of strings in the format
    string1a   string1b
    string2a   string2b
    string26000a string26000b
    all strings are always 4 characters in length.  For example,
    a123   jkdh
    b456   uusp
    How can use TestStand 2013 to input this data into local string array varaibles?  I also have legacy testers running TestStand 3.5, so I need a TestStand 3.5 solution as well.  Thanks in advance for any ideas.  Hopefully this can be done in TestStand without the use of LabView or LabWindows/CVI.

    Daniel E., thanks for the reply. 
         It is very frustrating to have to implement workarounds in order to access text in an external file when using TestStand.  TestStand already reads in text ini files, so it would probably take a TestStand software developer all of 1/2 day to write the code and 1/2 day to debug it.  Here I will restate the obvious.  Engineers have to deal with data, sometimes data generated from other applications.  Sharing data in a text file is one of the most basic functions (and one of the easiest to implement).  When I think of all the effort needed to support ActiveX, but NI did not see it fit to give TestStand users simple text file read/write functionality, it does not make sense to me.  Maybe it was too simple or mundane a task so it did not get developed?  Whatever the reason, I think users of TestStand deserve this basic functionality.
         Even if TestStand cannot read the data directly into array variables, it should provide some mechanism to read the text from the file, either line by line or all file text into a string, so the data could then be parsed into the array variables I need.
         I will pursue a CVI or LabView solution.  Please also know that I am not directing these comments at you, I do appreciate your reply.
    Regards,
    Ron

  • How to read continue binary string

    Hi,
    I have a encoder and it send me a continue string in ASCII. The port configuration is : 1 start bit, 7 data bits, 1 parity bit, 2 stop bits and termination character = x0D . And, the code is like this :
    ASCII code 31 (011 0001) = SB 1000 110 PB SB SB
    My problem is I can not cut the string at the good place.
    Thank you for your help.

    To find the termination characters, there are a number of vi's
    available to use such as "Search and Replace String", "Search/Split
    String", or "Search and Replace Pattern" as those all return an offest
    number where it has found the termination character.
    In order to reverse the sense (with the possibility of having 15 people
    find more efficient ways to do this like yesterday), use "String to
    Byte Array", then "Reverse 1D Array", then "Byte Array to String", and
    your data will be reversed.

Maybe you are looking for

  • Vid card for TV to HD Display yet?????/

    Aloha All, I am wondering where to find a vid card that allows cable hookup to see tv on my 30" HD display. I am not looking for a unit to record TV. I am looking for a card to fit into the pci express slot and be able to do both computer and TV func

  • I need Upgrade WiSM to 7.0.235.3

    I have a 6509-E with Sup WS-SUP720-3B IOS (s72033-ipservicesk9_wan-mz.122-18.SXF7) And i need upgrade my Wism to software version 7.0.235.3, and i have a question:  I have to update the ios Supervisor? or can i upgrade to 7.0.235.3 with  Supervisor I

  • Cannot see photos

    I have a bit of a problem with my aperture library, probably something silly I did, but would appreciate some advice. Here is the situation, something happened, I clicked restore masters (or something like that), and then aperture spend the night pla

  • Downloading a trial version of InDesign CC

    I cannot download a trial version of InDesign CC. How do I get the adobecreativecloud client?

  • "Not Responding" when importing FCP XML

    I'm trying to import a final cut XML file and it crashes everytime it gets to importing the files... Any tips or suggestions?