String to Date Conversion
Hi,
I need to convert a string to a Date format.
Input string can be in 2 formats: "mm-dd-yy" and "yyyy-mm-dd".
Thanks....
java.util.Date date = new java.util.Date();
sd = new java.text.SimpleDateFormat("yyyy-MM-dd");
System.out.println(sd.format(date));
sd = new java.text.SimpleDateFormat("MM-dd-yy");
System.out.println(sd.format(date));
Similar Messages
-
i have proubleam with string to date conversion, i out put date fromat is 2012-04-30T23:48:55.727-07:00 . so please help me the format conversion.
i wrote the method but it not workig
My method is
-(NSDate *)dateformstr:(NSString *)str
NSString *date = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSDateFormatter *dateFormate = [[NSDateFormatter alloc] init];
[dateFormate setDateFormat:@"yyyy-MM-dd'T'HH:mm:sssZZZZ"]
// NSDate *formatterDate = [dateFormate dateFromString:str];
return formatterDate;
but i did not the value and if i try othere formate i is working but my requiremet format is 2012-04-30T23:48:55.727-07:00.
can any help it out in this senario.Sorry Butterbean, but I'm interested in the answer to your question myself.
I've spent a few hours transfering my library from one computer to another and then find out that my ratings didn't transfer. Like you, I've spent many hours rating my 2000+ songs. I'm sure you have more, nevertheless, I want to find out how to get those ratings. They still show in my iTunes on my laptop but, when I go to the iTunes folder and display the details of at song, no rating is there. If you find out how to get them to display there in the iTunes folder, it seems that would be the key.
Hope you get your answer soon. -
String to date conversion problem
Hai braniees,
i am new to java.I have a problem in converting string to date.my code is this
dob="2/05/2005";
SimpleDateFormat sf=new SimpleDateFormat("dd/MM/yyyy");
Date dt=sf.parse(dob);
i this i am getting the error in the last line.the error is
" Unhandled exception type ParseException"
I am not able to getrid of this.
Thanks
anieshukI would advise against doing what ranjithcp suggested unless you are such a perfect programmer that you'll never get invalid data into your methods. Also what ranjithcp has failed to mention is that you'll have to put the throws instruction all over your code right up to your main method otherwise your just moving your error message up through your program.
You should always try and handle checked exceptions not throw them. -
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. -
Boolean Array to Hex String - LabVIEW Supplementary Data Conversion Library in version 12 please
Hello,
I would like to use the Boolean Array to Hex String.vi in LabVIEW Supplementary Data Conversion Library at http://zone.ni.com/devzone/cda/epd/p/id/3727
But it is version 4. Can someone give me the library in version 12? Attached herewith.
Attachments:
cnvrsion.zip 38 KBMass compiled in 8.2.1, which you can open with 2012.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Attachments:
convrzun.llb 65 KB -
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" -
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, -
Hi,
I have a file where fields are wrapped with ".
=========== file sample
"asdsa","asdsadasdas","1123"
"asdsa","asdsadasdas","1123"
"asdsa","asdsadasdas","1123"
"asdsa","asdsadasdas","1123"
==========
I am having a .net method to remove the wrap characters and write out a file without wrap characters.
======================
asdsa,asdsadasdas,1123
asdsa,asdsadasdas,1123
asdsa,asdsadasdas,1123
asdsa,asdsadasdas,1123
======================
the .net code is here.
========================================
public static string RemoveCharacter(string sFileName, char cRemoveChar)
object objLock = new object();
//VirtualStream objInputStream = null;
//VirtualStream objOutStream = null;
FileStream objInputFile = null, objOutFile = null;
lock(objLock)
try
objInputFile = new FileStream(sFileName, FileMode.Open);
//objInputStream = new VirtualStream(objInputFile);
objOutFile = new FileStream(sFileName.Substring(0, sFileName.LastIndexOf('\\')) + "\\" + Guid.NewGuid().ToString(), FileMode.Create);
//objOutStream = new VirtualStream(objOutFile);
int nByteRead;
while ((nByteRead = objInputFile.ReadByte()) != -1)
if (nByteRead != (int)cRemoveChar)
objOutFile.WriteByte((byte)nByteRead);
finally
objInputFile.Close();
objOutFile.Close();
return sFileName.Substring(0, sFileName.LastIndexOf('\\')) + "\\" + Guid.NewGuid().ToString();
==================================
however when I run the bulk load utility I get the error
=======================================
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 3 (NumberOfMultipleMatches).
==========================================
the bulk insert statement is as follows
=========================================
BULK INSERT Temp
FROM '<file name>' WITH
FIELDTERMINATOR = ','
, KEEPNULLS
==========================================
Does anybody know what is happening and what needs to be done ?
PLEASE HELP
Thanks in advance
VikramTo load that file with BULK INSERT, use this format file:
9.0
4
1 SQLCHAR 0 0 "\"" 0 "" ""
2 SQLCHAR 0 0 "\",\"" 1 col1 Latin1_General_CI_AS
3 SQLCHAR 0 0 "\",\"" 2 col2 Latin1_General_CI_AS
4 SQLCHAR 0 0 "\"\r\n" 3 col3 Latin1_General_CI_AS
Note that the format file defines four fields while the fileonly seems to have three. The format file defines an empty field before the first quote.
Or, since you already have a .NET program, use a stored procedure with table-valued parameter instead. I have an example of how to do this here:
http://www.sommarskog.se/arrays-in-sql-2008.html
Erland Sommarskog, SQL Server MVP, [email protected] -
How to do Data Conversion SSAS ?
I have fact table and a dimension table where the fields which I want to connect are of different data types i.e integer and string, So I need a help on data conversion how it is done in ssas .
Hello,
In DSV you can change the linked table into a "named query" and then you can do the data type conversion there, like
SELECT CONVERT(varchar(20), MyIntColumn) AS MyCharColumn
Olaf Helper
[ Blog] [ Xing] [ MVP] -
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;
} -
Hi Everyone,
I'm confused by the data conversion rule and how to do it in abap, could you help me about some of my questions?
1. How many ways to do data conversion ( like assignment .....)?
2. When using field symbol, we know we can assign reference to field symbol , and at mean time , we can casting type.
Is this kind of casting also a way to do data conversion?
3. In my real case, I have unknown type data to convert to xstring. the type could be any ( I, D, T, STRING......). Is there an easy way to implement that when I get the data reference, I only need to import it to a method and then the method return an xstring to me?
4. question 3 is about data->xstring, and how can I convert xstring back to the original data( should be the same type )?
Thanks and Regards,
AaronHi Aaron,
try this FM: CONVERSION_EXIT_ALPHA_INPUT
is useful for convert different data type, here an example:
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = A ( type unknown )
importing
output = B ( type xstring ).
Perhaps that helps,
Regards,
Davide -
I just upgrade my jdbc driver to "BEA's MS SQL Server Driver(Type 4)" in WLS 8.1. I got the following errors when executing rs.getTimestamp(1) with a NULL value fetched. Any idea?????
java.sql.SQLException: [BEA][SQLServer JDBC Driver]Unsupported data conversion.
at weblogic.jdbc.base.BaseExceptions.createException(Unknown Source)
at weblogic.jdbc.base.BaseExceptions.getException(Unknown Source)
at weblogic.jdbc.base.BaseData.unsupportedConversion(Unknown Source)
at weblogic.jdbc.base.BaseData.getTimestamp(Unknown Source)
at weblogic.jdbc.base.BaseResultSet.getTimestamp(Unknown Source)
at weblogic.jdbc.base.BaseResultSet.getTimestamp(Unknown Source)
at weblogic.jdbc.wrapper.ResultSet_weblogic_jdbc_base_BaseResultSet.getT
imestamp(Unknown Source)Steven Yip wrote:
I tried to run the application under WLS8.1sp4 and shown that its version
is 3.40.19 (012727.007216.008716); however, the problem persists.Hi Steven. I think something else must be wrong. I can't duplicate it.
Here's a small program. Change it to your user, password, dbms etc,
and see if you can alter it to get it to show the problem.
What is your table definition?
thanks,
Joe
import java.io.*;
import java.util.*;
import java.net.*;
import java.sql.*;
import weblogic.common.*;
public class ddora
public static void main(String argv[])
throws Exception
Connection c = null;
try
java.util.Properties props = new java.util.Properties();
props.put("user", "scott");
props.put("password", "tiger");
props.put("SID", "JOE");
Driver d = (Driver)Class.forName("weblogic.jdbc.oracle.OracleDriver").newInstance();
c = d.connect("jdbc:bea:oracle://JOE:1521", props);
System.out.println("Driver version is " + c.getMetaData().getDriverVersion());
Statement s = c.createStatement();
try{s.executeUpdate("drop table joe");} catch (Exception ignore){}
s.executeUpdate("create table joe "
+ " ( DATEOBJ DATE NULL)"
s.executeUpdate("insert into joe values(NULL)");
ResultSet rs = s.executeQuery("SELECT * FROM JOE");
rs.next();
rs.getTimestamp(1);
catch (Exception e)
{ e.printStackTrace(); }
finally
{ try {c.close();}catch (Exception e){} } -
Problem with String to Int conversion
Dear Friends,
Problem with String to Int conversion
I am having a column where most of the values are numeric. Only 4 values are non numeric.
I have replaces those non numeric values to numeric in order to maintain the data type.
CASE Grade.Grade WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade END
This comes the result as down
Grade
_0_
_1_
_10_
_11_
_12_
_13_
_14_
_15_
_16_
_17_
_18_
_19_
_2_
_20_
_21_
_22_
_23_
_24_
_3_
_4_
_5_
_6_
_7_
_8_
_9_
Refresh
Now I want to convert this value to numeric and do some calculation
So I changed the formula as below
cast (CASE Grade.Grade WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade END as INT)
Now I get the following error
View Display Error
_ Odbc driver returned an error (SQLExecDirectW)._
Error Details
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
_State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 1722, message: ORA-01722: invalid number at OCI call OCIStmtFetch. [nQSError: 17012] Bulk fetch failed. (HY000)_
SQL Issued: SELECT cast ( CASE Grade.Grade WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade END as Int) saw0 FROM "Human Capital - Manpower Costing" WHERE LENGTH(CASE Grade.Grade WHEN 'E1' THEN '20' WHEN 'E2' THEN '21' WHEN 'E3' THEN '22' WHEN 'E4' THEN '23' ELSE Grade.Grade END) > 0 ORDER BY saw_0_
Refresh
Could anybody help me
Regards
Mustafa
Edited by: Musnet on Jun 29, 2010 5:42 AM
Edited by: Musnet on Jun 29, 2010 6:48 AMDear Kart,
This give me another hint, Yes you are right. There was one row which returns neither blank nor any value.
I have done the code like following and it works fine
Thanks again for your support
Regards
Code: cast (CASE (CASE WHEN Length(Grade.Grade)=0 THEN '--' ELSE Grade.Grade END) WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' when '--' then '-1' ELSE Grade.Grade END as Int) -
Planning and Scoping- Data conversion and testing
hello Gurus
Good people i'm looking for your help in these areas.....
1) Planning and scoping for data conversion....we will be in the process of acquiring information from the client soon. So, what sort of information or questions do i need to get from the client and also the plan needed?
2) Test planning...... things i need to get from the client to prepare for this plan???
thanks
rashamHi,
the question which ou have asked is really very broad. so let me give some idea regarding the planning of data conversion. first of all you should identify which all objects you want to be transfered to SAP, obviously In MM material master, inforecord source list e.tc. then you need to decide which SAP tool you will be using to upload these data like LSMW, CATT e.t.c.
once it is decided what and how you are going to transfer then comes the Functional spec for data conversion in which you will give the details of data mapping in SAP. these FS will be translated to Tech Spec by technical consultant.
Test Planning,
first of all you will decide what type of testing you want to cary out like String test, Unit test, and integration test but these are decided by the testing team not Func consultant but anyway once it is decide how many level of testing is carried out then as a func consultant you will have to create test scenario for integration testing,
Regards
Vikrama
Maybe you are looking for
-
Will A 27 Inch Samsung LED Monitor work on my Macbook pro?
I have a Mid 2009 Macbook Pro and I am not sure what ports it has. I see 2 ports apart from the USB (2 ports), Power and LAN. I am planning to buy a 27 inch Samsung LED monitor for the laptop. Here are the Macbook specs: Processor - Intel Core 2 Duo
-
Hi Gurus, i need to assign queries to a role so that users having this role will be able to get the queries in their menu when they log into the system. How can I do it? Partha
-
I'm using Adobe LiveCycle 8.0. I just created my first form. There is a few fields I would like to make required. I already have the TAB order the way I need it to be. Here's what I need to happen: If a user starts filling out the form & does not fil
-
Help me!
-
Using Pegasus as LUN via a SANLink
Hi, My company currently is using MetaSAN with a fairly complex dynamic drive system from Compellant. The reliablity of the drive system has been good, but the peformance and cost/performance ratio is not ideal for Multimedia production. The Compe