How to convert string date to long (or Unix date)?

I'm having difficulty in converting a user supplied date in the format mm/dd/yyyy to a long format such as 1035462807000. Since it's being entered by the user I can't just use the current system date. Any suggestions? Thanks!
Dave

Hi man, tsith Gave a good beggining, why dont you try the next code
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;
public class DateToUnix{
    public static void main(String args[]){
        getDateAsLong();
    public static void getDateAsLong(){
        String sStartDate = "12/01/2002";
        Date theDate;
        DateFormat sdf= new SimpleDateFormat("MM/DD/yyyy" );
        try {
            theDate = sdf.parse( sStartDate );
        }catch(ParseException e ){
            theDate = new Date();
        System.out.println( "Converted Start Date:" + theDate.getTime());
}No mather how you get a Date object, the value you are looking for is a long, and you can get it from such object with the getTime() method.
Take a look at the Java API @ [http://java.sun.com/j2se/1.4.1/docs/api/java/util/Date.html#getTime()]

Similar Messages

  • How to convert String date to java sql date

    I have an html form for entering the Date on retreving that value in a java servlet i get it as a string i want to convert that date to SQL date format so that i could use setDate() method of the java.sql.Date class to update the date value in the database.
    i used the following way but i need the code without using the deprecated ones.
    String delDate = (String)p_Request.getParameter("deleteDate");
    [b]java.util.Date utilDate = new java.util.Date(delDate);
    java.sql.Date deleteDate = new java.sql.Date(utilDate.getTime());
    custCode = (String)p_Request.getValue("custCode");
    thanx in advance.

    Check out the later posts in http://forum.java.sun.com/thread.jspa?threadID=647681&messageID=3814745#3814745

  • How to convert string to an integer in SQL Server 2008

    Hi All,
    How to convert string to an integer in sql server,
    Input : string str="1,2,3,5"
    Output would be : 1,2,3,5
    Thanks in advance.
    Regards,
    Sunil

    No, you cannot convert to INT and get 1,2,3 BUT you can get
    1
    2
    3
    Is it ok?
    CREATE FUNCTION [dbo].[SplitString]
             @str VARCHAR(MAX)
        RETURNS @ret TABLE (token VARCHAR(MAX))
         AS
         BEGIN
        DECLARE @x XML 
        SET @x = '<t>' + REPLACE(@str, ',', '</t><t>') + '</t>'
        INSERT INTO @ret
            SELECT x.i.value('.', 'VARCHAR(MAX)') AS token
            FROM @x.nodes('//t') x(i)
        RETURN
       END
    ----Usage
    SELECT * FROM SplitString ('1,2,3')
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to convert numeric data to binary decimal in java

    How to convert numeric data to binary decimal in java Pleas egive me code example

    There is no numeric data. It's all binary. If you're talking about Strings, look at the Integer class.

  • How to convert julian Date into Calendar Date

    Hi,
    I want convert julian Date to calendar Date (mm/dd/yyyy or mm/dd/yy format) in java.
    Can any one help me how to convert julian date to calendar Date.
    Thanks,
    Krishore.

    import java.util.*;
    import java.text.*;
    public class jdate {
    Calendar date;
    public jdate(int j)
    date = Calendar.getInstance();
    date.set(Calendar.DAY_OF_YEAR, j);
    public String toString()
    SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
    return (formatter.format( date.getTime() ));
    public static void main(String args[])
    if(args.length == 1)
    int j = Integer.parseInt(args[0]);
    jdate julian = new jdate(j);
    System.out.println("Julian date(" + j + ") = " + julian.toString());
    }

  • 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 to convert system Date into DD-MMM-YYYY Format

    hi friends,
    please help me How to convert system Date into DD-MMM-YYYY Format.
    Regards
    Yogesh

    HI..
    data: w_dt(11) type c,
             w_month(2),
             w_mon(3).
    w_month = p_date+4(2). **p_date = given date**
    case w_month.
    when '01'.
    w_mon = 'Jan'.
    when '02'.
    w_mon = 'Feb'.
    when '03'.
    w_mon = 'Mar'.
    when '04'.
    w_mon = 'Apr'.
    when '05'.
    w_mon = 'May'.
    when '06'.
    w_mon = 'Jun'.
    when '07'.
    w_mon = 'Jul'.
    when '08'.
    w_mon = 'Aug'.
    when '09'.
    w_mon = 'Sep'.
    when '10'.
    w_mon = 'Oct'.
    when '11'.
    w_mon = 'Nov'.
    when '12'.
    w_mon = 'Dec'.
    endcase.
    Now...
      concatenate p_date6(2)  '-'  w_mon  '-'   p_date0(4)  into w_dt.
    write w_dt.

  • How to convert siebel date to following format?

    Hi,
    How to convert siebel date to following format?
    01-01-2011 5:00 AM (dd-mm-yyyy hh:mm AM)
    01-JAN-2011 5:00 AM (dd-MON-yyyy hh:mm AM)
    01/01/2011 5:00 AM (dd/mm/yyyy hh:mm AM)
    Please suggest functions for conversion. Have tried few but didnt work.
    Thanks.

    Excerpts from
    http://bipconsulting.blogspot.com/2010/01/my-date-doesnt-like-me-with-siebel.html
    ".. the date data generated by Siebel with the IO is in ‘MM/DD/YYYY HH:MI:SS’ format, so it is something like ‘10/09/2008 05:31:13’. And BI Publisher doesn’t recognize that this is a date data because it’s not presented in the ‘Canonical’ format!.."
    "...There are two possible and reasonable workarounds to overcome this issue. The first one is to use one of the Siebel’s extended function ‘totext()’ to convert the Siebel date format to the ‘Canonical’ date format before the BI Publisher’s date related function comes in..."
    Please read on the above link to find out how to actually resolve this issue.
    Good Luck
    (please if this provides a solution for you grant the points and close this thread. Thanks!)
    Jorge

  • How to convert CLOB data (now it is in html format) to Normal text format

    Hi,
    Can anybody let me know the solution for how to convert CLOB data into normal Text.In my case the table column having CLOB datatype and the data is in html format.when i run the report the column is displaying html tags .Now i need to convert that html tags into normal text.
    Pl. let me know if any one know the solution.
    Regards,
    Thulasi.K

    LONG has been depricated since 8i so I don't believe there is a general solution to go backwards short of reloading the data.
    Justin

  • How to convert mongodb data  to oracle

    The requirement is I need to convert the mongodb or JSON data which is provided to us in Oracle format
    so that it can be used in Oracle Data Integrator ODI
    Edited by: 918554 on Aug 9, 2012 10:37 PM
    Edited by: 918554 on Aug 9, 2012 11:02 PM
    Kindly reply soon its urgent
    Edited by: 918554 on Aug 9, 2012 11:03 PM

    918554 wrote:
    how to convert mongodb data to oracleThis is NOT an Oracle problem or solution.
    http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Mapping+Chart

  • How to convert a data set into a xml data and vice versa

    i am new to oracle with xml..
    my aim is to convert a data set into a xml data and vice versa..
    my work is as follows...
    my query:
    select rggpk,rggcode,rggname from ms_regiongeo
    to convert a data set into a xml*
    select XMLType(trim(replace(dbms_xmlgen.getXML('select rggpk,rggcode, rggname from ms_regiongeo'),'<?xml version="1.0"?>',''))) XML_DATA from dual;
    (this works fine and output of this query is as follows..)
    <ROWSET>
    <ROW>
      <RGGPK>201</RGGPK>
      <RGGCODE>Asia</RGGCODE>
      <RGGNAME>Asia</RGGNAME>
    </ROW>
    <ROW>
      <RGGPK>1</RGGPK>
      <RGGCODE>OTH</RGGCODE>
      <RGGNAME>Others</RGGNAME>
    </ROW>
    <ROW>
      <RGGPK>21</RGGPK>
      <RGGCODE>COB</RGGCODE>
      <RGGNAME>Africa and Yemen</RGGNAME>
    </ROW>
    <ROW>
      <RGGPK>2</RGGPK>
      <RGGCODE>AUS</RGGCODE>
      <RGGNAME>Australia</RGGNAME>
    </ROW>
    <ROW>
      <RGGPK>23</RGGPK>
      <RGGCODE>IND</RGGCODE>
      <RGGNAME>Indian Sub Continent</RGGNAME>
    </ROW>
    <ROW>
      <RGGPK>24</RGGPK>
      <RGGCODE>TVM</RGGCODE>
      <RGGNAME>North America</RGGNAME>
    </ROW>
    </ROWSET>
    and to reverse this process, I tried a query like this..*
    select EXTRACTVALUE (XML_DATA,'ROWSET/ROW/RGGPK') as EMP_ID
    from(
            select XMLType(trim(replace(dbms_xmlgen.getXML('select rggpk,rggcode, rggname from ms_regiongeo'),'<?xml version="1.0"?>',''))) XML_DATA from dual
    )tab1but failed.. and raised with an eror: ORA-19025
    help me..
    regards,
    john

    Hi-
    my aim is to convert a data set into a xml data  You can refer to the below posts
    Adding namespace to XML output
    Re: how to convert table data in xml format based on the xsd.

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

  • Essbase 9.3 Calc scripts. Pb with dates. How to convert (string = number) ?

    Hello,
    I've a problem with Essbase(Planning?) Scripts on version 9.3. It looks simple but I do not find any (clean) solution :
    On my Essbase database, I have a member called "Reference_Date" on my axis Indicators. It is a date data type, that is to say, it displays a number corresponding to a YYYYMMDD format. For example : 20091029 for October 29th 2009.
    In calc scripts I often need to compare the month included in that "Reference_Date" with the current Member of my Time Axis (I have 12 Months members based on the format M02 for February for example). The final aim is to calculate a number of complete years since that "Reference_Date".
    But theses two elements are not of the same "type" (one is a number value and the other is a "member" in Time Axis). So I'm forced to convert one of this two elements in order to compare it.
    For example I can extract the month value of the "Reference_Date"' and put an "M" before it to have a Time member equivalent or I can convert the member Name M10 to a number (10))
    in both cases I have the same type problem : I don't know how to convert a string into a number nor how to convert a number into a string.
    (For example @CONCATENATE doesn't work with numbers). and that my only remaining problem.
    I didn't find any Essbase Function which do this (conversion number <=>string).
    Is anyone have an Idea ?
    Thanks for your help
    Best regards

    I don't know any way for you to compare your data against your metadata. Not directly. To me it makes little enough sense to try that I'm not surprised the developers didn't provide for it.
    I've converted member names to strings, manipulated the strings (calc script functions are not good at this), and turned them back into member names, but that's really the only use I've had for string manipulation. I don't think an equivalency operator even exists for string data. And I see no way to begin thinking of a member name, once converted to a string, as a number.
    It makes even less sense to me to try thinking of a data value as a string. Even text values in Sys 11 are stored as numbers. Not encoded characters, but just a number to look up somewhere.
    I think you can do what you want though, with something like this...
    IF (@ISMBR("FY08"))
    vYr = 2008;
    ELSEIF (@ISMBR("FY09"))
    vYr = 2009;
    ENDIF;
    IF (@ISMBR("M01"))
    vMth = 1;
    ELSEIF (@ISMBR("M02"))
    vMth = = 2;
    ENDIF;
    "Years_Since_Reference" = ((vYr * 100) + Mth) - ("Reference_Date" / 12);
    Obviously, the math will need some work, coz that doesn't actually work, but the logic above essentially turns your metadata into numbers, which is what you are after.
    Good luck,
    -- Joe

Maybe you are looking for

  • Dunning notices not printed

    Hello Gurus, I've been trying to run transaction F150. before running this i manually cleared all the dunning data in the vendor master except for the dunning procedure, configured in FBMP. I run this and get the following message.  "Credit memo 15XX

  • NVIDIA driver 6md647ww does not install on W701 with Windows 7 64 Bit

    Hello, I have downloaded the nvidia driver 6md647ww (311.00), 64 bit version, and can't install on a Windows 7 64-bit system. It says "no compatible device found". The strange thing is, although the decompression routine and the window asking to star

  • Procurement indicator field mandatory

    Dear Friend's, Can is it possible to make procurement indicator field mandatory while planning material in project builder at material component overview screen.Because i have to enter 3 different procurement indicator's. (PReq + Reservation for WBS

  • OpenDocument - Parameters is lost when opening the report with token

    Hello, we want to migrate our BO Enterprise (XI R3) from Tomcat to IIS. We developed an application in which you can open reports by using the opendocument-url. It was no problem with our old BO-Enterprise Server (tomcat/jsp), but with our new BO-Sys

  • Error installing LabWindows/CVI Trial

    I got the following error while installing the trial version. Any siggestions? Thanks! Solved! Go to Solution.