Convert a date to string

hi,
I have a got a date d = Wed Nov 05 00:00:00 GMT 2008
i need to convert this into a string of the format MM/dd/yyyy.

You may use SimpleDateFormat class
--Sachin.                                                                                                                                                                                                                   

Similar Messages

  • 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 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 the date of string to datetime format 'MM/dd/yyyy' when the system date format is 'dd/MM/yyyy'.

    I need convert the date of string format 'MM/dd/yyyy' to datetime format 'MM/dd/yyyy' when the system date format is 'dd/MM/yyyy'.Since
    I need to search values based on date where my database datetime  is 'MM/dd/yyyy' format.

    In my opinion you should re-consider the assumption that the date picker returns a string. Maybe it is able to return a
    DateTime object directly instead of string. Then you will pass this value as a parameter of SQL query. This should work regardless of computer configuration.
    Otherwise, follow the previous string-based approaches.

  • How to convert DateField date to String ?

    Hi,
    I'm trying to convert DateField date to String.
    How can I do it because Data class does not have String converting
    methods...
    Thanks
    Krzysztof

    Hello,
    you can get an instance of Calendar and use it with the date as a long integer.
    public Calendar cal=Calendar.getInstance();
    myDate=dateField.getDate();
    cal.setTime(myDate);
    myDateString=cal.get(Calendar.DATE)+"."+cal.get(Calendar.MONTH)+"."+cal.get(Calendar.YEAR));
    Try it.
    Unfortunately I have found that the MIDlet get a day less when I use the same long integer that I got from an application on PC. I don't realy understand why but I' still searching.
    I hope it is usefull for you.
    ValeriuS

  • How to convert a date to string

    hi i have a date field in the format yyyy-MM-dd i wan to make this as string
    Date lastDate = stmt.getDate(3);this will return a date 2003-11-13 i wan to make it as a string

    hi all,
    i found the solution thanks

  • Convert Binary Data to string in MsSQL

    Hello,
    I am running a query for MSSQL database to get some file content which is stored in Binary data format in the database.
    I want to copy that file which is in the binary data format to a file in the text format.
    How can I do this?
    Regards,
    Sravanthi

    This is the expected result in the file that stores the data.
    ResultElement     
    WshOutputTest
    Errors/Failures     
    1 / -
    Incident     
    Error: some unexpected result     
    function main()     
    some additional info; eg. stacktrace
    Incident     
    Warning: some warning message     
    function main()
    some additional info; eg. stacktrace
    But I am getting the following stored in my file:::
    PK   FSH;
    output.xmlíT»NÃ@œ‰8¥‚
    *Æ)xH)      ‚R[ñÅ9AìȾðøy`nϖs1nBY>_vvfŸÊÏw„>±ÄÞ¡Q¢‚AWà§8ãWÉ1£=%š#ôÜá„^ü5BŒC ½+¬©iqËSSßñ-u&‚YŒù:»Ó™Ò²À#+9¯A©øDÔ*ù|¯y®E1fôìåN‘Ëëì»ü~¼ÕK{ ·0ßK֕2ÞbÞ*
    *©\‰–fŸW<gRyJk¹Ñ'—Ã6?T¦ÍOÈÐÿ‹x[³cwñCÌRÛ0^ˆy¼éù}–.y»|ýF(ÚéЎ%f—ÓÕu]›“¿Ù„õ§’§WNdÿLíy)û–q÷”¨'Ìá•ßRnZ"·ªa•Ãž:ÎßóûÏl?‚ÍQbm=w™k¸‹ûÙî>[‡ôÿyŸ_PKÙõ¡¬N    PK    FSH;Ùõ¡¬N  * 
    *output.xmlPK 8 †*
    I tried getting the Binary Stream with UTF-8 encoding style and no encoding style too but it didnt work.
    Thanks,
    Sravanthi.

  • How to convert Raw data to string in Unicode conversion

    Hi All,
    I want to convert my report in Unicode while conversion we are getting error as "The key of internal table "IRESBD" contains components of type "X" or "XSTRING". The "READ TABLE IRESBD" statement is not permitted for such tables"
    Regards,

    Thanks for reply ,
    I tried to use the FM but not able to get any value ? is this FM converts all internal table or used to convert one field value.
    My report is Unicode so i need to internal table while reading Internal table which contains fiield as GUID_16 type Raw is showing error.
    Regards,

  • How to convert Date to String

    Hi All,
    I have a dimension member in my classic plannnig application whose datatype is Date,
    Now i want to use that member inside the following function:
    @TODATE(<date format goes here> , <date string goes here>);
    e.g
    @TODATE("mm-dd-yyyy" , "Dimension Member Name");
    Now the second parameter to this function is of string type, whereas the data type of my member is "Date", so is there any way to convert this date to string?
    Notes:-
    I am using the above script inside the member formula.
    I run the code with some static value e.g.
    @TODATE("mm-dd-yyyy" , "01-12-2011"); and it works quite fine so i am pretty much sure that issue is related to incompatible data types.

    Have a look at the following post it should give you an idea - Re: @DatePart formula produces constant result
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Concat Date and String!

    Hello,
    My requirement is that I need to concat a string with a date. I tried to convert the date to char but I am not getting the date format and then want to contact with the string.
    here is the requirement:
    Contact Date: 12/08/2011.
    In order to do this, I tried to convert the date into string but having difficulty in getting the date format.
    any help is appreciated.
    Thanks -

    manyam16 wrote:
    Hello,
    My requirement is that I need to concat a string with a date. I tried to convert the date to char but I am not getting the date format and then want to contact with the string.
    here is the requirement:
    Contact Date: 12/08/2011.
    In order to do this, I tried to convert the date into string but having difficulty in getting the date format.
    any help is appreciated.
    Thanks -The "tricky" part to what you are asking for is that when you cast a date column as char, the format may change. For example, when I look at my system date as is (it is a date field), the format is as follows:
    1/26/2012 5:53:11 AM
    When I cast it as CHAR, it appears as follows:
    2012/01/26 05:53:11
    Why am I saying this? Because the details of the next step will be determined by where the characters are in the string. For this exercise, I will assume that after casting to CHAR, the format is as you say. Then the stringing should look something like this:
    Contact Date: 12/08/2011. SUBSTRING(CAST("your date column" AS CHAR) FROM 1 FOR 2) ...to give you the 12
    SUBSTRING(CAST("your date column" AS CHAR) FROM 4 FOR 2) ...to give you the 08
    SUBSTRING(CAST("your date column" AS CHAR) FROM 7 FOR 4) ...to give you the 2011
    So concatenating them, you get:
    SUBSTRING(CAST("your date column" AS CHAR) FROM 1FOR 2)||'/'||SUBSTRING(CAST("your date column" AS CHAR) FROM 4 FOR 2)||'/'||SUBSTRING(CAST("your date column" AS CHAR) FROM 7 FOR 4)
    Now you can concatenate your text to the above string...

  • 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.

  • Convert Date to String but maintain a MM/DD/YY format

    I have converted a date field  to a string without a problem.  However, when I use it in a report, the entire date/time from the original date field prints.  How do I get only the MM/DD/YY format to print once I've converted it to a string or how do I convert the field  to a MM/DD/YY format before converting it to a string?

    THis should give you what you are looking for...
    ToText({TableName.DateField}, "MM/dd/yy")
    note: the MM instead of mm... "M" is for months, "m" is for minutes...
    HTH,
    Jason

  • Converting any date string to GMT standard

    Hi All,
    I want to convert any date string to GMT standard.
    The date string may be like this.
    "Sat Sep 15 14:23:40 IST 2001"
    I have tried to change my defaultTimeZone .
    But I don't know why it's not working.
    Is there something to do with Locals?
    Can anyone please tell me the way to
    accomplish that ?
    Thanks in advance.
    Sujoy

    Java stores all the dates in GMT Format , considering the machines TimeZone Setting ....and also i guess date has methods like toGMTString() and toLocaleString() . To convert the date to GMT i guess u can just say toGMTString() of the date . If u have the stringified version of date
    just make a new Date(String) and then calling toGMTString of it .

  • I have a string 2012-05-22T23:23:42.263-07:00. so i want to convert in date with indian time zone   can any one help me out

    i have a string 2012-05-22T23:23:42.263-07:00. so i want to convert in date with indian time zone   can any one help me out

    What does this have to do with iPhone tech support?

  • Problem converting U8 array to date-time string

    Hi All,
    How can I convert U8 array (time_t data type from C dll) to date time string?
    A dll function that I am calling has a structure of string, integer and time_t as one of the parameters. Instead of passing cluster, I pass an array of U8 of the size that the structure should be. All the members of the strcuture and parsed correctly except the date/time.
    Function Parameter:
    typedef struct {
    Int AlarmState ;
    Int AlarmGrade ;
    TCHAR AlarmMessage [100] ;
    time_t AlarmTimeStamp ;
    } WV_ALARM_INFO ;
    Total size = 4 + 4 + 100 + 4 = 112
    Using Call Library Function, I set the parameter type to Array of U8 and size 112.
    After the array is populated when the function is called, I have done the following to interpret date and time.
    1) Using Extract Zero Terminated String.VI I converted U8 array (of size 4) to string.
    2) Type casted string to integer (I32).
    3) Swap bytes
    4) Swap Words
    5) Format Date/Time String.
    Please see the attached screenshot for visual display of the above.
    Ideas on why the year is incorrect?
    Mimansa
    Attachments:
    Time.JPG ‏102 KB

    Hi Mimansa,
    Is it only the year that is incorrect? Also, where did you find that ABC\0 VI that you use 3 times? Did you make it or is it in a labview library somewhere?
    Thanks,
    Laura

Maybe you are looking for

  • Logic pro 9.1.6 (1700.43) crashes all the time under lion with mac mini server

    Hi, I run logic pro 9 with a mac mini server under lion 10.7.2 and it crashes all the time I get this crash report: Anyone knows how to solve this? Thanks Process:         Logic Pro [1877] Path:            /Applications/Logic Pro.app/Contents/MacOS/L

  • I need a replacement keyboard for a Lenovo 3000 C200 Model# 8922-2FU

    My wife dumped a glass of water on her laptop and I am having a really hard time finding a replacement keyboard. Why do wives love to break the machines? Thanks

  • Installing (using) JSSE to Visual Age

    Hi all, I have installed JSSE 1.0.2 in JDK 1.3.1 successfully.. Everything is working fine. However what I need to do is use JSSE under Visual Age 3.5... (my VA is iv3-4 jdk 1.2.2 (patched.)) I am importing three jar files which comes with JSSE but s

  • Version of outlook

    How to know the version of outlook through JAVA prg???? Thanks

  • Bapi for address change

    hi friend, i change  customer telephone noumber in revelent T.code in my R/3 system and i want to update this change in CRM system so kindly give me sutiable bapi for this change.