String into date format

Hi
I was wondering if anyone knew how to convert a string into different formats,
to enable it to be stored in a mysql db.
I was wondering anyone you knew how to convert:
- String into the date format yyyy-mm--dd
- String into time format 00:00:00
- string to double
Ive tried:
c_date = java.sql.Date.valueOf(f_date);
System.out.println("conversion data: " +c_date);
c_time = java.sql.Time.valueOf(f_time);
System.out.println(" time converted data: "+c_time);
// string to double conversion
c_change = java.lang.Double.valueOf(f_change);
System.out.println(c_change);
My class doesnt execute this at all?
Also,
SimpleDateFormat sdft = new SimpleDateFormat("yyyy-MM-dd");
c_date = sdft.format(f_date);
System.out.println(c_date);
.. but this method returns the error incompatible types?
Any suggestions would be helpful.. thanks in advance..

Friends i've got similar kind of problem...can you help me
here is my code. When i try to print the user entered date (dd/MM/yyyy)(which i am storing in a string) the program dispalys nothing. and everey time i enter a valid date it displas "invalid From date entered ". I need to store the user entered date into a string because i need that for further use. All my intesion is to get two dates from user in dd/MM/yyyy. Strore them in certain variable. Check if they are valid or not. and make sure todate is either equal or greater than fromdate. Please help me to solve this problem.
public class EDTDateValidation extends JFrame implements ActionListener{
private JLabel fromlabel;
private JLabel tolabel;
private JTextField fromtxt;
private JTextField totxt;
private String fmt ="dd/MM/yyyy";
private java.lang.String fromdate;
private java.lang.String todate;
private JButton buttonOK;
private JButton buttonCancel;
private Date theDate;
private Date date1;
private Date date2;
private JPanel mainPanel;
SimpleDateFormat dtformat = new SimpleDateFormat(fmt);
public EDTDateValidation(){
super("Date Validation");
dtformat.setLenient(false);
mainPanel=new JPanel();
mainPanel.setLayout(null);
fromlabel = new JLabel("From Date");
tolabel = new JLabel("To Date");
buttonOK = new JButton("OK");
buttonCancel = new JButton("Cancel");
fromdate = new String();
todate = new String();
fromtxt = new JTextField(10);
totxt = new JTextField(10);
fromdate = fromtxt.getText();
todate = totxt.getText();
mainPanel.add(fromlabel);
fromlabel.setBounds(20,20,50,15);
mainPanel.add(tolabel);
tolabel.setBounds(20,50,50,15);
mainPanel.add(fromtxt);
fromtxt.setBounds(90,20,130,20);
mainPanel.add(totxt);
totxt. setBounds(90,50,130,20);
mainPanel.add(buttonOK);
buttonOK.setBounds(70,80,71,23);
mainPanel.add(buttonCancel);
buttonCancel.setBounds(150,80,71,23);
buttonOK.addActionListener(this);
buttonCancel.addActionListener(this);
setContentPane(mainPanel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(247,140);
setResizable(false);
//pack();
public static void main(String args[]) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
catch(Exception e) {
System.err.println("Could not load Look and Feel" + e);
EDTDateValidation edtDateVal = new EDTDateValidation();
edtDateVal.setVisible(true);
public void actionPerformed(ActionEvent e) {
if(e.getSource() == buttonOK){
System.out.println(fromtxt.getText());
System.out.println(fromdate); //THIS PRINTS BLANK
System.out.println(todate); //THIS ASWELL
try {
Date date = null;
date = dtformat.parse(fromdate);
System.out.println("valid From date entered!");
catch(Exception f) {
System.out.println("Invalid From date entered!");
// textField1.setText("");
return;
try {
Date date = null;
date = dtformat.parse(todate);
System.out.println("valid TO date entered!");
catch(Exception f) {
System.out.println("Invalid To date entered!");
// textField1.setText("");
return;
}

Similar Messages

  • Converting a string into Date format

    I am currently using a JSP.
    I currently need to convert a string that holds a date in "dd/mm/yyyy" format to the jva.sql.Date format.
    Any ideas as to what the proper way of doing this is?
    Many thanks ppl

    public java.sql.Date parseDate(String s) {
         java.text.DateFormat dateFormatter= new java.text.SimpleDateFormat("dd/MM/yyyy");
         return new java.sql.Date(dateFormatter.parse(s).getTime());

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

  • How to convert a String to Date format?

    the user enter a date in string format and the date is save in the database.
    The problem i am facing is i want to change from String to Date format.
    Here is my codes:
            public boolean insertData() throws Exception {
            boolean validFlag = false;
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date d = df.parse("05/18/05");
            String MY_DATE_FORMAT = "yyyy-MM-dd";
            String jobAdvertisementDate = new SimpleDateFormat(MY_DATE_FORMAT).format(d);
            String sql = "INSERT INTO companyjob (CompanyID,JobID, JobAdvertisementDate ) " +
                    " VALUES ('" + companyID + "','" + jobID + "', '" + jobAdvertisementDate + "')";
            System.out.println(sql);
            validFlag = executeSQL(sql);
            return validFlag;
        }The date is save under jobAdvertisementDate.
    My netbeans shows an error. There's a red line under DateFormat and parse inside my codes.
    PLease help me. Reply asap!!

    BebeGirl wrote:
    My netbeans shows an error. There's a red line under DateFormat and parse inside my codes.
    Red Line? Sounds ominous. I wonder what it means.
    So...what does the error say?

  • How can i convert this data(00000000) into date format(yyyy-MM-dd)

    Hi,
    i am using this method to convert date format from string.
    public static string FormatDate(string inputDate, string inputFormat)
                System.DateTime date = DateTime.ParseExact(inputDate, inputFormat, null);
                string datepresent = DateTime.Now.Date.ToString("yyyy-MM-dd");
                return datepresent;
    its working properly,
    but when input data is like 00000000 i am getting error this is not valid.
    how can i convert this into date format any help..!

    Have you tried the above code:
    I can see it is working with both Date and DateTime destination nodes.
    Map:
    Functoid Parameters:
    Functoid Script:
    public static string FormatDate(string inputDate, string inputFormat)
    string datepresent;
    if (inputDate == "00000000")
    datepresent = "0000-00-00";
    else
    System.DateTime date = DateTime.ParseExact(inputDate, inputFormat, null);
    datepresent = date.ToString("yyyy-MM-dd");
    return datepresent;
    Input:
    <ns0:InputDateString xmlns:ns0="http://DateFormat.SourceSchema">
    <DateString>00000000</DateString>
    </ns0:InputDateString>
    Output:
    <ns0:OutputDate xmlns:ns0="http://DateFormat.DestinationSchema">
    <Date>0000-00-00</Date>
    </ns0:OutputDate>
    If this answers your question please mark as answer. If this post is helpful, please vote as helpful.

  • String to DATS format conversion in XI.

    Hello Experts,
    I am using Powerbuilder system to get my Legacy data.In Powerbuilder Date needs to be supplied in STRING format.So I am giving String Format (dd-mmm-yyyy).
    However, at SAP end, Date needs to be in DATS format (Standard SAP yyyymmdd) .
    In Message Mapping I have given I/P structure as String and O/P structure as DATS format. When I test mapping in XI, it gives me Parseable error.
    Can anybody tell me, is there any way in XI to convert from String to DATS format so that I do not get Parseable error.
    Please Help!!!!

    Lokesh,
    With XI there is a date transformation function under date category there you need to provide source date format and target date format..
    I have used the same for fetching the data from oracle..and posting into SAP..it works fine..
    Try this ..this will solve ur problem....you just need to see what is the exact date format used by powerbuilder internally...
    Regards,

  • String to DATS format Conversion

    Hello Experts,
    I am using Powerbuilder system to get my Legacy data.In Powerbuilder Date needs to be supplied in STRING format.So I am giving String Format (dd-mmm-yyyy).
    However, at SAP end, Date needs to be in DATS format (Standard SAP yyyymmdd) .
    In Message Mapping I have given I/P structure as String and O/P structure as DATS format. When I test mapping in XI, it gives me Parseable error.
    Can anybody tell me, is there any way in XI to convert from String to DATS format so that I do not get Parseable error.
    Please Help!!!!

    Lokesh,
    With XI there is a date transformation function under date category there you need to provide source date format and target date format..
    I have used the same for fetching the data from oracle..and posting into SAP..it works fine..
    Try this ..this will solve ur problem....you just need to see what is the exact date format used by powerbuilder internally...
    Regards,

  • I want convert string to date format in Oracle

    Dear All
    I want convert string to date format in Oracle,Format is given below
    'Friday, 02 March 2012 2:44 PM' to '02/03/2012 2:44 PM'

    >
    Hi Parwez,
    I want convert string to date format in Oracle,Format is given below
    'Friday, 02 March 2012 2:44 PM' to '02/03/2012 2:44 PM'SELECT TO_DATE('Friday, 02 March 2012 2:44 P.M.', 'DAY, DD MONTH YYYY HH:MI A.M.') from dual;
    As well as what the other poster suggested, look here: http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm#i34924
    HTH,
    Paul...

  • Adding time into date format

    Hi
    Is there any easier way to add time value "now" into a date format with time value 00:00
    I managed to add the time
    Value(dateVariable)+(Value(Now())-Value(Today()))
    I just wander if there is any easiest way to do that or if there is any planed options for that?
    Thanks

    Hi Brutton
    I know about this. My scenario is that I use my custom date picker where user can pick a date. For easier date picking I use date format (today) and then adding day ,month or year into that so the date formant is in time 00:00. I
    need to add now time in that date so I can sort entry by date and also by time in a collection I managed to do that with the format mentioned above but I just wander if there is also any other way to do that. We already have excellent code DateAdd where we
    can add days months and years but I can't really add time with this code. I don't think that DateAdd can add time into date format or at least I haven't figure it out yet. If not there would be nice to have A TimeAdd code then instead of calculations

  • How to convert Milliseconds into Date format

    Hi all,
    I am getting the output of a variable in milliseconds format, how can I convert it into date format
    For ex: I am getting input variable as 1366664691000 and I need to convert it to April 22, 2013 5:04:51 PM EDT ( or of SOA format). is there any function for this in XSL or XPath?
    Thanks,

    It is working fine if i test it in provided site...
    But it is returning "-1366664691001", If i am running it in EM. This is the code in my xsl
    <?xml version="1.0" encoding="UTF-8" ?>
    <?oracle-xsl-mapper
    <!-- SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY. -->
    <mapSources>
    <source type="WSDL">
    <schema location="../JavaProcess.wsdl"/>
    <rootElement name="process" namespace="http://xmlns.oracle.com/SampleApplication/JavaEmbeddingActivity/JavaProcess"/>
    </source>
    </mapSources>
    <mapTargets>
    <target type="WSDL">
    <schema location="../JavaProcess.wsdl"/>
    <rootElement name="processResponse" namespace="http://xmlns.oracle.com/SampleApplication/JavaEmbeddingActivity/JavaProcess"/>
    </target>
    </mapTargets>
    <!-- GENERATED BY ORACLE XSL MAPPER 11.1.1.4.0(build 110106.1932.5682) AT [TUE MAY 07 10:21:02 EDT 2013]. -->
    ?>
    <xsl:stylesheet version="1.0"
    xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
    xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
    xmlns:mhdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.mediator.service.common.functions.MediatorExtnFunction"
    xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
    xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue"
    xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:med="http://schemas.oracle.com/mediator/xpath"
    xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath"
    xmlns:bpm="http://xmlns.oracle.com/bpmn20/extensions"
    xmlns:xdk="http://schemas.oracle.com/bpel/extension/xpath/function/xdk"
    xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:bpmn="http://schemas.oracle.com/bpm/xpath"
    xmlns:ora="http://schemas.oracle.com/xpath/extension"
    xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator"
    xmlns:ldap="http://schemas.oracle.com/xpath/extension/ldap"
    xmlns:client="client"
    exclude-result-prefixes="xsi xsl bpws xp20 mhdr bpel oraext dvm hwf med ids bpm xdk xref bpmn ora socket ldap">
    <xsl:template match="/">
    <xsl:variable name="lastMTime" select="1366664691000"/>
    <xsl:copy-of select="$lastMTime"/>
    <client:processResponse>
    <client:result>
    <xsl:value-of select='xsd:dateTime("1970-01-01T00:00:00") + $lastMTime * xsd:dayTimeDuration("PT0.001S")'/>
    </client:result>
    </client:processResponse>
    </xsl:template>
    </xsl:stylesheet>

  • How to convert string into date datatype

    hi! there
    i've a date in string format like MM/dd/yyyy
    eg:String sDate = "01/30/2002";
    and i want to convert this string format into java date format
    same as 01/30/2002 only
    when i write like this
    SimpleDateFormat formatter = new SimpleDateFormat ("MM/dd/yyyy");
              String sDate = "1/11/2002";
              java.util.Date oDate = formatter.parse(sDate);
    i'm getting the output
    Fri Jan 11 00:00:00 GMT+05:30 2002
    i just want the out put like 01/30/2002
    plz,help me

    Hi,
    Just use back the SimpleDateFormat object you defined.
    String myDateInStr = formatter.format(oDate);
    this will format a java.util.Date object to a string representation according to the format you specified in the instantiation of SimpleDateFormat object.

  • How to convert string into date

    Hi all,
    I m new to JDeveloper
    I m taking the date as a string then passing it as a string in the method.
    I want to convert tht string into the date of format (DD-MON-YYYY) or any other format
    require yur assistance in this job.
    THANKXX in advance
    ankit

    Is this what you are looking for:
    java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("dd-MMMMM-YYYY");          
    java.util.Date date1 = null;
    try
       date1 = formatter.parse("Thu Jun 3 09:09:30 2004");
    catch(Exception e)
       e.printStackTrace();
    System.out.println("Date1 in millis : " + date1.getTime());
    System.out.println("Date1 in string : " + date1);
    java.util.Date date2 = new java.util.Date(date1.getTime());
    System.out.println("Date2 in string : " + date2);or look at http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html for more options

  • Change string into Date?

    Hi guys
    I am writing a voice web application. My problem is when i speak the date it gets inserted into the textbox as a number e.g. 01012005 however when i pass this to my jsp then i get an error cause this not a valid date format.
    Can you help me change the number into a date e.g. insert / to split the day month and year up? so i can insert it into my database.
    Thanks

    You could use java.text.SimpleDateFormat to convert Strings to Date and back.
            SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy");
            Date d = sdf.parse("01012005");ram.

  • Need to convert into date format

    Hi all,
    I need to convert '2008-11-26T11:07:38-06:00' [YYYY]-[MM]-[DD]T[HH]:[MM]:[SS][TIMEZONE]
    in format 'YYYY-MM-DD HH:MM:SS'.
    Thanks in advance.

    >
    Thank you for your reply
    But it is giving me output as '26-NOV-08'
    And I want in format '2008-11-26 07:38' i.e 'YYYY-MM-DD HH:MM'.
    >
    Then you are not looking for a date, You are looking for a string.
    The date format that gets displayed is dependent on nls_date_format parameter.
    If you want a string in the format you asked, then,
    SELECT TO_CHAR ( TO_DATE ( '2008-11-26T11:07:38-06:00', 'YYYY-MM-DD"T"HH24:MI:SS"-06:00"'), 'YYYY-MM-DD HH24:MM:SS')
      FROM DUAL;Or if you just want the date to be displayed like that then
    Do,
    SQL> alter session set nls_date_Format="YYYY-MM-DD HH24:MI:SS";
    Session altered.
    SQL> SELECT TO_DATE ( '2008-11-26T11:07:38-06:00', 'YYYY-MM-DD"T"HH24:MI:SS"-06:00"') dt
      2    FROM DUAL;
    DT
    2008-11-26 11:07:38
    SQL> G.

  • Formating string to date format in vc

    hai,
    function module in production return a date in type of char10. now i need to convert into proper data format.
    can any one help me.

    data: l_date type datum
          , l_d(10)
    l_date = sy-datum.
    write l_date to l_d. -> This statement will convert into user date format
    write:/ l_d.  
    ...Naddy

Maybe you are looking for

  • Need advise on SQL,plsql developer career and future

    Hi all, I need all your advise in making an important decisions of my career path.I work in the IT field and have about total 4-5 years of work experience involving development and testing in a product based organization. Presently-i have got chance

  • PCR WF in MSS

    Hello All, I have been trying to configure workflow for use in PCR forms in MSS. I think I have already configured workflow, for the most part, but I am getting errors in the form of emails after initiating PCRs. For a PCR without approval, I am gett

  • Why can't I open RAW camera files with Photoshop 6 anymore??

    Attempted to open file, as I've done hundreds of times before. I get pop up window saying software can't open file. Nikon cameras used in my office are all supported.

  • Cisco AnyConnect::How to hide "Security Warning : Untrusted Certificate"

    Whenever I connect to my ASA using Anyconnect client, attached warning message always appear and there is no option to Trust it or import certificate so that it should not appear next time. Anyone please help to make the option visible to trust certi

  • Problem importing Adobe Connect recording into Captivate 6.0

    Hello, Not having found something about this via search, I'm asking the question.  I am in tech support for University of Missouri-Extension and we use Connect and create many recordings for later share.  I am able to import these FLV recordings into