Convert date "yyyy-MM-dd" to "MM/dd/yyyy"
Hi,
First of all thank you for helping in advance.
I am a new rookie in Java language. However, I have question regarding to converting the date format that I get from mysql to the regular US display date format.
The question is I got the date from mysql in "yyyy-MM-dd" and this has been assigned to a string type. For the next step, I would like to convert this string into the format "MM/dd/yyyy".
I realize there is a lot of posting and some sample code for this issue.
I have tried using the following code:
String cur_date = "2003-08-30";
SimpleDateFormat theinput = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat theoutput = new SimpleDateFormat("MM/dd/yyyy");
System.out.println(theoutput.format(theinput.parse(cur_date)));
The header I have included:
import java.text.SimpleDateFormat;
import java.util.Date;
I actually don't know what is wrong, and really need help on that.
Thank you.
Hmmm... you code seems to work fine?
import java.util.*;
import java.text.*;
public class DateTest {
public static void main(String[] args) {
try {
String cur_date = "2003-08-30";
SimpleDateFormat theinput = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat theoutput = new SimpleDateFormat("MM/dd/yyyy");
System.out.println(theoutput.format(theinput.parse(cur_date)));
} catch (ParseException pe) {
System.out.println(pe);
}produces the output
08/30/2003Regards,
/Håkan
Similar Messages
-
Hi,
I am getting the error "The conversion of a varchar data type to a datetime data type resulted in an out-of-range value."
when converting date in format Date in varchar(50) format MM/DD/YYYY HH:MM into YYYY-MM-DD format using MS SQLServer 2008 R2.
Please note that the date in column is Date(varchar(50), null).
I used the following syntax:
SELECT CONVERT(VARCHAR(10), Date, 102) AS Day
FROM dbo.[RCap_2G MM/Operator]
WHERE (CONVERT(VARCHAR(10), Date, 102) > { fn NOW() } - 1)As noted above, either use ISDATE or TRY_CONVERT with the correct conversion style number:
-- SQL Server 2012 code
DECLARE @Date varchar(50) = '10/23/2006 10:20';
SELECT TRY_CONVERT(DATE, @Date, 101) AS Day
-- 2006-10-23
Datetime conversion blog:
http://www.sqlusa.com/bestpractices/datetimeconversion/
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
Convert Date format from YYYYMMDD to MM/DD/YYYY --issue with Mapping
Hi All ,
I have IDOC(DESADV.DELVRY03-> file ) scenario which i am working on . While debugging noticed that the field :
E1EDT13\NATNZ -Data Transformation(from yyyymmdd to mm/dd/yyyy)-Target .This works
But say if IDOC doesn't pass any value (For Good's issue) I get Error during debugging : RuntimeException in Message-Mapping transformation: Unparseable date: ""
I did check thsi blog : Convertinf Date format from YYYY-MM-DD to MMDDYYYY but this is about the Data Transformtaion.
I tried using constants , create if , -these function doesn't work /not applicle in this case
Could you please provide inputs as to how to handle two condition :
1. With date -- then transform
2.Else , pass nothingHi Varalakshmi,
Plese try to use UDF for date conversion and include logic which would check the Space value from the source structure.
so if there is space return as such
else.
perform the conversion logic.
Convertinf Date format from YYYY-MM-DD to MMDDYYYY
(The conversion logic has been provided by micheal in the thread you have provided in the query)
Thanks,
Ram. -
Convert Date Format from DDMMYY to DD/MMM/YYYY
Hi,
Thanks in Advance.
Is there any function Module to Conver the Given Date in the given Below Format.
DD / MMM / YYYY
For Example if the given date is 16072009 then it should print as 16 / JUL / 2009
Regards:
Sridhar.Jhi
use the below code it may help u
PARAMETERS: p_date TYPE d.
DATA: datestring TYPE char11, l2 TYPE T247-KTX.
CALL FUNCTION 'ISP_GET_MONTH_NAME'
EXPORTING
date = p_date
language = 'E'
month_number = '00'
IMPORTING
shorttext = l2 .
IF sy-subrc <> 0.
CONCATENATE p_date6(2) '/' l2 '/' p_date0(4) INTO datestring.
WRITE: datestring .
surya reddy -
Need to convert Date from calendar to String in the format dd-mom-yyyy
Need to convert Date from calendar to String in the format dd-mom-yyyy+..
This is absolutely necessary... any help plz..
Rgds
ArwinderLook up the SimpleDateFormat class: http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
Arwinder wrote:
This is absolutely necessary... any help plz..For you maybe, not others. Please refrain from trying to urge others to answer your queries. They'll do it at their own pace ( if at all ).
People on the forum help others voluntarily, it's not their job.
Help them help you.
Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
(Yes I know it's on JavaRanch but I think it applies everywhere)
---------------------------------------------------------------- -
How to Convert Date (DD.MM.YYYY) to be just DD
Hi experts,
I have no idea how to convert Date format (DDMMYYYY) to be just DD.
Example:
I have date: 31.10.2009
now i just want to show in report as 31.
I just known if we just want to show month only, we could use the 0CALMONTH2. but how if i need the day only?
Are there any way, either in query (BEx) or modeling (Routine/Formula in Update Rules or Transfer Rules) which could fulfill the requirement?
Many thanks..
Warm Regards,
TikaHi,
go through the link below and modify according to your requirement
Date conversion from YYYYMMDD to DD.MM.YYYY
Regards,
Marasa. -
How to convert date from "yyyymmdd" to "MM/DD/YYYY" format
1. I have one BLDAT field in my internal table.
its getting updated from input file.
2. The value in the input file is like yyyymmdd.
So the internal table field is filled like this
"YYYYMMDD".
3. After this,I have to compare this internal table
field with BSAD table.
4. The BLDAT field in BSAD table is in the format of
"MM/DD/YYYY".
5. the BLDAT field is having diff format in internal table and BSAD table.So I am unable to check this value.
How to convert it as like the BSAD table format."MM/DD/YYYY" format.
Thanks in advance!!Using the WRITE statement
data: gd_date(10). "field to store output date
* Converts date from 20020901 to 09.01.2002
write sy-datum to gd_date mm/dd/yyyy.
OR u can
CONCATENATE gd_date+4(2) gd_date+6(2) gd_date+0(4)
into gd_date seperated by '/' .
Hope this helps.
Kindly reward points and close the thread for the
answer which helped u OR get back with queries. -
To convert date dd/mm/yyyy in Timestamp format
hi
I want to convert date of format dd/MM/yyyy, which get from user by PropertyUtils.getSimplePropetrty(form, "startDate"); , into Timestamp format...........
please help me in this regard.......
1904ya mean it from java.sql.Timestamp
and also I am using getTime() method but giving
root cause:
org.apache.commons.beanutils.ConversionException: Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff
and
Caused by: java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff
at java.sql.Timestamp.valueOf(Timestamp.java:160)
at org.apache.commons.beanutils.converters.SqlTimestampConverter.convert(SqlTimestampConverter.java:157) -
To convert dec date 732,677 in to dd.mm.yyyy format
Hi,
i have to convert dec date 732,677 in to dd.mm.yyyy format .
plz help me out
its urgent
regards,
Nishu Guptause this Fm
CONVERSION_EXIT_INVDT_INPUT
<b>CONVERSION_EXIT_INVDT_output.</b>
i hope u r referring to Tcurr-gdatu.
refer this code for the working ..
data : date like sy-datum,
date1(10) type c,
val like sy-datum,
datum(8) type n .
date = sy-datum.
write:/ date.
concatenate date4(2) date6(2) date+0(4) into val.
CALL FUNCTION 'CONVERSION_EXIT_INVDT_INPUT'
EXPORTING
input = val
IMPORTING
OUTPUT = datum.
write:/'tcurrformat' datum.
*clear val.
CALL FUNCTION 'CONVERSION_EXIT_INVDT_OUTPUT'
EXPORTING
input = datum "----
>pass this
IMPORTING
OUTPUT = date1.
write:/'normal format', date1.
Please close your previous threads.
regards,
vijay -
Function module to convert date form yyyy/mm/dd to dd/mm/yyyy format
Can any one tell me Function module to convert date form yyyy/mm/dd to dd/mm/yyyy format?
have a look at the WIKI FAQs...they are very useful
https://www.sdn.sap.com/irj/sdn/wiki?path=/display/abap/abapDevelopmentand+Programming&
For this it says:
<i>How to convert a date to internal or external format?
Use the functions modules CONVERT_DATE_TO_EXTERNAL or CONVERT_DATE_TO_INTERNAL
to convert the date. When converting to external format, the date format from the user's user profile will be used. When converting to internal format, the result will be in YYYYMMDD format.</i> -
Function module to convert date form yyyy/mm/dd to mm/dd/yyyy format
can any one tell meFunction module to convert date form yyyy/mm/dd to mm/dd/yyyy format
hi
good
try this
report zrich_0001.
tables s002.
data ilikp type table of likp.
ranges: r_datum for sy-datum.
select-options: s_spbup for s002-spbup.
start-of-selection.
r_datum-sign = 'I'.
r_datum-option = 'BT'.
r_datum-low = s_spbup-low.
r_datum-low+6(2) = '01'.
if s_spbup-high is not initial.
r_datum-high = s_spbup-high.
r_datum-high+6(2) = '01'.
else.
r_datum-high = r_datum-low.
endif.
r_datum-high4(2) = r_datum-high4(2) + 1.
r_datum-high = r_datum-high - 1.
append r_datum.
select * into table ilikp from likp
where erdat in r_datum.
thanks
mrutyun^ -
OWB 10gR1 Convert Date format (mm-dd-yyyy) to (yyyy-mm-dd)
Hi All,
In OWB 10gR1, I have flatfiles with Date fields having the format (mm-dd-yyyy). I want to load this data into the Staging table in (yyyy-mm-dd) format. How could I do this conversion in my staging mapping ?
Using external tables is not an option.
An detailed answer will be extremely helpful.
Thanks community.Wich is this field's datatype in database? Is it date or char? If you are going to store it as a date datatype, you don't have to worry about the date format.
Have you tried using the Expression Operator to perform the date string conversion in your mapping? Sorry about this lame drawing, but I think it will help you understand:
source_table ------------ALL_COLUMNS_EXCEPT_DATE_DATATYPE-------TARGET_TABLE
| |
+-------EXPR{TO_DATE(DATE_FIELD, 'DATE_FORMAT')}--+In this example, you'll use an expression operator to convert the date string in the format you want. Map other attributes directly to your target table (or other transformations you need to perform).
This is the generated script of a dummy plan I've built here:
OPTIONS ( ERRORS=50, BINDSIZE=50000, ROWS=200, READSIZE=65536)
LOAD DATA
CHARACTERSET WE8MSWIN1252
INFILE '{{LOC_FILE.RootPath}}load.csv'
INTO TABLE "LOAD_TARGET"
APPEND
REENABLE DISABLED_CONSTRAINTS
FIELDS
TERMINATED BY ';'
OPTIONALLY ENCLOSED BY '"'
"COD" POSITION (1) INTEGER EXTERNAL ,
"NOME" CHAR ,
"DATA" CHAR "to_date( :\"DATA\" , 'yyyy-mm-dd')"
)Regards,
Marcos -
How to convert date (dd/mm/yyyy) to week no. calendar?
hi all,
I have a question about if user enters 12/12/2004(dd/mm/yyyy), which week is that? I just know week no. should from 01 to no more than 53. How to convert date to week no.?
Thanksselect to_char(sysdate,'IW'),to_char(sysdate,'wW') from dual;
for IW, the week 2 starts on the first monday after 1.Jan, for WW, the week 2 starts on 8. Jan.
HTH
Laurent Schneider
OCM DBA -
How to convert date format to MM/DD/YYYY
Hi,
How to convert date format to MM/DD/YYYY.
Thanks,
Senthilhi,
tri with this function module
data :l_date(10) type c
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
DATE_INTERNAL = SY-DATUM
IMPORTING
DATE_EXTERNAL = l_date.
this function module converts date from 20050601 to external format which is specified in user profile
cheers,
sasi -
Convert date format from MONTH-YEAR to dd/mm/yyyy
Dear All
i want to get parameter in form of MONTH-YEAR AND WANT TO CONVERT DATE INTO 'THIS FORMAT dd/mm/yyyy' IT GIVES ME ERROR PLEASE GUIDE.
SELECT
TO_CHAR (PTP.END_DATE,'MONTH-YY') ,
to_date ( TO_CHAR (PTP.END_DATE ,'DD-MONTH-YYYY') ,'dd/mm/yyyy'),
--- i want to gent parameter in from of MONTH-YEAR AND WANT TO CONVERT DATE INTO 'THIS FORMAT dd/mm/yyyy' IT GIVES ME ERROR PLEASE GUIDE
to_date ( TO_CHAR (PTP.END_DATE ,'MONTH-YYYY') ,'dd/mm/yyyy'),
ADD_MONTHS((to_date ( TO_CHAR (PTP.END_DATE ,'MONTH-YYYY') ,'dd/mm/yyyy'),-1)
--- i want to gent parameter in from of MONTH-YEAR AND WANT TO CONVERT DATE INTO 'THIS FORMAT dd/mm/yyyy' IT GIVES ME ERROR PLEASE GUIDE
ptp.END_DATE PERRIODS_NAME
from per_time_periods ptp
Regards
Edited by: user10941925 on Nov 28, 2011 12:23 AMHello just check
SQL> select hiredate from emp;
HIREDATE
17-DEC-80
20-FEB-81
22-FEB-81
02-APR-81
28-SEP-81
01-MAY-81
09-JUN-81
09-DEC-82
17-NOV-81
08-SEP-81
12-JAN-83
03-DEC-81
03-DEC-81
23-JAN-82
14 rows selected.
SQL> select to_char(hiredate,'month-year') from emp;
TO_CHAR(HIREDATE,'MONTH-YEAR')
december -nineteen eighty
february -nineteen eighty-one
february -nineteen eighty-one
april -nineteen eighty-one
september-nineteen eighty-one
may -nineteen eighty-one
june -nineteen eighty-one
december -nineteen eighty-two
november -nineteen eighty-one
september-nineteen eighty-one
january -nineteen eighty-three
december -nineteen eighty-one
december -nineteen eighty-one
january -nineteen eighty-two
14 rows selected.
SQL> select to_char(hiredate,'dd/mm/yyyy') from emp;
TO_CHAR(HI
17/12/1980
20/02/1981
22/02/1981
02/04/1981
28/09/1981
01/05/1981
09/06/1981
09/12/1982
17/11/1981
08/09/1981
12/01/1983
03/12/1981
03/12/1981
23/01/1982
14 rows selected.
SQL>
Maybe you are looking for
-
Hi, There is no setting for 23.97 in Flash Media Live Encoder. Is this what is generated when the frame rate is set to 24? Thanks. - Joel
-
Hello, I am trying to implement the function specgram of matlab in Labview. In matlab I enter a sound signal sig1 (50.000 x 2 array) with a sampling rate Fs1 = 22050. I also define a window size of 512. I execute b1 = specgram(sig1(:,1),windowsize,
-
Error "no link to maintenance cycle" happens after reset to previous phase
Experts: I have a CHaRM project which has successfully transported a few changes into production. Then I use action "set to previous phase" several times to set this project to "development without release". Then I create another change request by s
-
Adobe reader will not read aloud?
I have Window 8 on an HP touch smart laptop, I downloaded the latest adobe and I try to get it to read aloud and it wouldn't work.
-
When buying an app it asked me questions for security but i dont remember them
when buying an app it asked me questions for security but i dont remember them