Convert Calender to date with MM-DD-YYYY
I want to convert calendar object to date with the format of DD-MM-YYYY
How to do this?
Calculating Java dates: Take the time to learn how to create and use dates
Working in Java time: Learn the basics of calculating elapsed time in Java
Formatting a Date Using a Custom Format
Parsing a Date Using a Custom Format
Similar Messages
-
Convert java.sql.date to dd.mm.yyyy format
Hi,
Can any one tell me how to convert java.sql.date to dd.mm.yyyy format
Regards,
H.V.SwathiHi ,
Create a simple data type of type java.sql.date and give the format in it as "dd/MM/yyyy". This will work i guess.
Regards
Ishita -
How to Convert Calender to Date
Hi.
I have Calender object (MM dd,yyyy), I wanted to convert this into Date object in the format of "yyyy-mm-dd". Can any one please give me code to do this ?
Thanks
Sarav.Use Calendar.getTime() to get a Date object corresponding to the point in time that the Calendar represents.
But note that Dates don't have formats. If you want the time formatted in a particular way, use a java.text.SimpleDateFormat. -
Converting string to date in mm/dd/yyyy format
Hi,
I used simpledateformat to convert date to "MM/dd/yyyy" format.
Now when i want to insert into db, i want the value as date object instead of string [returned by format method of SimpleDateFormat]
what should i do?
Date dt = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
System.out.println("Formatted date is coming as "+sdf.format(dt));
Date dt1 = sdf.parse(sdf.format(dt);
System.out.println("parsed date is coming as " +dt1);
output :
1 SOP returns 11/07/2007 [current date]
2 SOP returns Wed Nov 07 00:00:00 GMT+05:30 2007If you are using PreparedStatements setDate method, you need a java.sql.Date object, not a Java.util.Date object. You can create an sql.Date object from a util.Date object as follows:
java.sql.Date sqlDate = new java.sql.Date(dt.getTime());And, if you are not using PreparedStatement and its setDate method, then change now.
Doing
Date dt1 = sdf.parse(sdf.format(dt));is meaningless. You format the date to string, then parse the string back to a date? Why? Why not just use the original Date object? And you won't get a sql.Date object that way, either, as the DateFormat classes return a util.Date object.
Edit: And for more info:
A Date does not have a format. It is simply a number. The "format" only comes into play when printing the String representation of the Date, and that is not handled by the Date object itself (except when calling toString either explicitly or implicitly). -
Comparing Converted Text To Date With Date Column
I have a query where I need to break out a text column into a date format and then compare that column against another column in the same table which is already date format. I tried using a sub query to avoid doing it in two steps, but get an:
'ORA 01858' a non numeric character was found where numeric was expected
error message which obviously has something to do with the formating of the date in the subquery: the types don't match.
Note: clock_num is a text column and contains numbers that are supposed to be dates like 070111 - hence the need for conversion into a date type to match the stat_date which is date column type. I do not have contol over the data in this column. It is not my table, it is the company's table and I must use it!
So my quesion is what syntax/function do I use to get the clock_nbr expression type to match the eff_date type.
Or is there a different way to go about doing the same thing without using the subquery?
Any assistance is appreciated..
SELECT
me.ssn,
FROM
member_enroll me
WHERE me.ssn = '999999999'
AND me.stat_date <
(SELECT to_date(substr(me.clock_num,1,2)||'/' || substr(me.clock_num,3,2)|| '/' ||substr(me.clock_num,5,2),'mm-dd-yy') as clock_nbr
FROM member_enroll me
WHERE me.ssn = '999999999')user12296489 wrote:
I wasn't assuming that all the dates were correct. But that is where I made the error. But the reason I didn't see the error was that I didn't know if the way I had the substr function set up with the subquery was correct. I thought that was the problem and so wanted to make sure that was correct before I moved on. As I pointed out, there is a much simpler way to convert the string to a date using a format mask that matches the string data rather than parsing the data using SUBSTR and converting it to a different format before calling TO_DATE.
It turns out that the reason you posted your function was actually what was holding it up. I had forgotten to include enough criteria in the subquery to return only the 1 record that had a valid clock_num. Once I did that, the query worked - without your function.Just be aware that though it works today, it may not work tomorrow when the query plan changes.
So, now, onto the issue that you brought up, I don't know how to integrate that function you posted into my query. I have no knowledge of creating functions in pl/sql. I tried placing it before the query and it ran but returned no records You need to create the function once whereas you would run the query many times. I'm not sure what application you're using to interact with the database. If you run just the CREATE FUNCTION DDL statement, does that work? If you're using SQL*Plus, you'd see something like this with the "Function created." feedback.
SQL> CREATE OR REPLACE FUNCTION my_to_date( p_str IN VARCHAR2 )
2 RETURN DATE
3 IS
4 l_date DATE;
5 BEGIN
6 BEGIN
7 l_date := to_date( p_str, 'MMDDYY' );
8 EXCEPTION
9 WHEN OTHERS THEN
10 l_date := null;
11 END;
12
13 RETURN l_date;
14 END;
15 /
Function created.>
Here is what I did. It doesn't error out. It says 'done in 0.156 seconds', but no records are returned. when I replace the function you gave (and rem out your function) with the to_date function, it returns 1 record. If I don't rem out your function and use the to_date function, it runs, but again, no records are returned.
select me.subs_ssn,
me.clock_num,
my_to_date(mbr02.mbr02_clock_num) as clock_num
from odw.mbr02_member_enroll_info mbr02
where mbr02.mbr02_subs_ssn = '999999999'
and mbr02.mbr02_grp_id = '00000'If you only have the function call in the SELECT list, the presence or absence of the function cannot possibly change the number of rows that are returned. So if your description is of the behavior of this particular query, something is very wrong. It is possible that the CLOCK_NUM column could be NULL if the MBR02_CLOCK_NUM column is in an invalid format. But the other two columns would have to be populated here if they are populated when you simply remove the call to the function.
Justin -
How can i convert a the date format 'm/d/yyyy hh:mi:ss AM' to 'MM/DD/YYYY HH:MI:SS AM' in Oracle
I have a query
select UPPER(t.val_10) "TYPE", count(val_3) "Number of Transfers"
from table1 t
where t.is_active = 1
and t.val_4 = 'INBOUND'
and to_date(to_date(val_5,'MM/DD/YYYY HH:MI:SS AM'), 'DD/MM/YY') between to_date(to_date('01/08/2008 00:00:00','DD/MM/YYYY HH24:MI:SS'), 'DD/MM/YY') and add_months(to_date(to_date('01/08/2008 00:00:00','DD/MM/YYYY HH24:MI:SS'), 'DD/MM/YY'),1)
group by UPPER(t.val_10)
order by UPPER(t.val_10)
I get the error [ORA-01861: literal does not match format string which i think is because
val_5 has the values in the following format:
8/29/2008 6:31:10 PM
Does anyone have an answer?
Thanks in advance
Edited by: user2360027 on 26-Mar-2009 03:50first off, you've got to_date(to_date(...)) - NEVER do this - you're forcing an implicit to_char which can cause all sorts of problems!
What is the data type of your column val_5? If it's DATE then your query is simply:
select UPPER(t.val_10) "TYPE",
count(val_3) "Number of Transfers"
from table1 t
where t.is_active = 1
and t.val_4 = 'INBOUND'
and val_5 between to_date('01/08/2008','DD/MM/YYYY') and add_months(to_date('01/08/2008','DD/MM/YYYY') ,1)
group by UPPER(t.val_10)
order by UPPER(t.val_10)If it's a varchar2 (why, oh why, oh why, ...?!), then your query should be:
select UPPER(t.val_10) "TYPE",
count(val_3) "Number of Transfers"
from table1 t
where t.is_active = 1
and t.val_4 = 'INBOUND'
and to_date(val_5, 'mm/dd/yyyy hh:mi:ss AM') between to_date('01/08/2008','DD/MM/YYYY') and add_months(to_date('01/08/2008','DD/MM/YYYY') ,1)
group by UPPER(t.val_10)
order by UPPER(t.val_10)Remember that dates in DATE format are stored in an internal Oracle format - in order for you to tell Oracle that your string is a date, you need to use to_date. When you want to retrieve a date, you need to use to_char to put it into the format you want to see it in.
Remember also that your nls_date_format defines the default format that you'll see a date, which is what is used in the implicit conversion that oracle does when you select a date:
SQL> alter session set nls_date_format='dd/mm/yyyy hh24:mi:ss';
Session altered.
SQL> select sysdate from dual;
SYSDATE
26/03/2009 11:01:53
1 row selected.
SQL> alter session set nls_date_format='mm/dd/yy hh12:mi:ss AM';
Session altered.
SQL> select sysdate from dual;
SYSDATE
03/26/09 11:02:24 AM
1 row selected.It doesn't make sense to convert something that's already in a DATE format into a DATE format - in order to do that, oracle has to first change the date into a string, and it does that by using the nls_date_format parameter setting - if you're working with dates-in-strings that are in a different format, then all sorts of problems arise, as you have found out! -
Problem with date format dd/mm/yyyy. But I need to convert yyyy-mm-dd.
Dear friends,
I have the problem with date format. I receiving the date with the format dd/mm/yyyy. But I can upload to MySQL only in the format of yyyy-mm-dd.
how should I handle this situation, for this I've created these code lines.But I have some problem with these line. please help me to solve this problem.
String pattern = "yyyy-mm-dd";
SimpleDateFormat format = new SimpleDateFormat(pattern);
try {
Date date = format.parse("2006-02-12");
System.out.println(date);
} catch (ParseException e) {
e.printStackTrace();
System.out.println(format.format(new Date()));
this out put gives me Tue Apr 03 00:00:00 IST 2007
But I need the date format in yyyy-mm-dd.
regards,
maza
thanks in advance.Thanks Dear BalusC,
I tried with this,
rs.getString("DATA_SCAD1")// where the source from .xls files
String pattern = "yyyy-MM-dd";
SimpleDateFormat format = new SimpleDateFormat(pattern);
try {
Date date = format.parse("DATA_SCAD1");
System.out.println(date);
} catch (ParseException e) {
e.printStackTrace();
System.out.println(format.format(new Date()));
this out put gives me Tue Apr 03 00:00:00 IST 2007
But I want to display the date format in yyyy-mm-dd.
regards,
maza -
Problem with date format "dd-MM-yyyy"
hi all,
i am using jdev 10.1.3.2
My application ADF Swing app.
in my database i have a table employee which contains "birthday".
my problem is that i must use date format"dd-MM-yyyy".
i added this format into "formatinfo.xml" file.
than i choose it in my EO.
i create a form which contains employees.
for example i have an employee with a birthday=25-10-1970
in my text field if user puts "1970-10-25"'which is not the best format) he will have a correct result "25-10-1970"
but if user puts "25-10-1970" he will have as result "21-02-0031" which is not the real value.
please help me.
thanks.
PS: i did some research before posting but i didn't find yetRouz,
Did you try what i said before?
* Open you EntityObject
* Expand the attribute tree
* Choose your DOB attribute
* Choose the Control hints pane on the right
* Choose Formater: Simple date format
* Choose Format mask dd-MM-yyyy
Run your application and try it.
This is how i change the format and it works perfectly.
I uses the correct format to show the date and it enables me to edit the date using the format mask dd-MM-yyyy
Edit: I just tried it myself. I can only reproduce it by removing my mask. Ergo, the application expects the default american format yyyy-MM-dd. By entering a date in the format dd-MM-yyyy the framework will convert it to yyyy-MM-dd and you'll end up with 0031-02-21.
CONCLUSION follow the steps i discribed above to set your mask and you'll be fine.
Message was edited by:
Smolders Johan -
SQL * Loader : Load data with format MM/DD/YYYY HH:MI:SS PM
Please advice how to load data with format MM/DD/YYYY HH:MI:SS PM into an Oracle Table using SQL * Loader.
- What format should I give in the control file?
- What would be the column type to create the table to load data.
Sample data below;
MM/DD/YYYY HH:MI:SS PM
12/9/2012 2:40:20 PM
11/29/2011 11:23:12 AM
Thanks in advance
AvinashHello Srini,
I had tried with the creation date as DATE datatype but i had got an error as
ORA-01830: date format picture ends before converting entire input stringI am running the SQL*LOADER from Oracle R12 EBS front-end.
the contents of my control file is
LOAD DATA
INFILE "$_FileName"
REPLACE
INTO TABLE po_recp_int_lines_stg
WHEN (01) = 'L'
FIELDS TERMINATED BY "|"
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
INDICATOR POSITION(1) CHAR,
TRANSACTION_MODE "TRIM(:TRANSACTION_MODE)",
RECEIPT_NUMBER "TRIM(:RECEIPT_NUMBER)",
INTERFACE_SOURCE "TRIM(:INTERFACE_SOURCE)",
RECEIPT_DATE "TO_CHAR(TO_DATE(:RECEIPT_DATE,'MM/DD/YYYY'),'DD-MON-YYYY')",
QUANTITY "TRIM(:QUANTITY)",
PO_NUMBER "TRIM(:PO_NUMBER)",
PO_LINE_NUMBER "TRIM(:PO_LINE_NUMBER)",
CREATION_DATE "TO_CHAR(TO_DATE(:CREATION_DATE,'MM/DD/YYYY HH:MI:SS AM'),'DD-MON-YYYY HH:MI:SS AM')",
ERROR_MESSAGE "TRIM(:ERROR_MESSAGE)",
PROCESS_FLAG CONSTANT 'N',
CREATED_BY "fnd_global.user_id",
LAST_UPDATE_DATE SYSDATE,
LAST_UPDATED_BY "fnd_global.user_id"
{code}
My data file goes like
{code}
H|CREATE|123|ABC|12/10/2012||||
L|CREATE|123|ABC|12/10/2012|100|PO12345|1|12/9/2012 2:40:20 PM
L|CORRECT|123|ABC|12/10/2012|150|PO12346|2|11/29/2011 11:23:12 AM{code}
Below is the desc of the table
{code}
INDICATOR VARCHAR2 (1 Byte)
TRANSACTION_MODE VARCHAR2 (10 Byte)
RECEIPT_NUMBER NUMBER
INTERFACE_SOURCE VARCHAR2 (20 Byte)
RECEIPT_DATE DATE
QUANTITY NUMBER
PO_NUMBER VARCHAR2 (15 Byte)
PO_LINE_NUMBER NUMBER
CREATION_DATE TIMESTAMP(0)
ERROR_MESSAGE VARCHAR2 (4000 Byte)
PROCESS_FLAG VARCHAR2 (5 Byte)
CREATED_BY NUMBER
LAST_UPDATE_DATE DATE
LAST_UPDATED_BY NUMBER {code}
Thanks,
Avinash -
Convert varchar2 field into date formatted: DD-MON-YYYY
Thanks in advance for anyone's help on this matter as I know it takes your time and expertise. I am pretty new to SQL but learning my way through it just have an issue with a text to date field conversion. It is an Oracle 10g database and I am writing in SQL. There is a field called Demand which is formatted in varchar2 format of ddmmyy. There is also a field that is formatted as a date called Payment which is formatted as DD-MON-YYYY.
Essentially I need to do a simple Payment >= Demand, however as you can see that is some issue with that being a varchar2 field. Does anyone know if it is possible to do that type of expression against those two fields. Was thinking about possibly converting the varchar2 to a date but not sure how to get to that DD-MON-YYYY format.
Also there are situations where this Demand field will often times be null as it would have never recieved any outbound correspondence in the past and would not have a date at all.
Thanks
Edited by: user10860766 on Aug 18, 2009 8:14 AM
Edited by: user10860766 on Aug 18, 2009 8:19 AMHi,
It's hard to detect bad dates in pure SQL, especially if you need to be precise about when February 29 is valid.
It's easy with a user-define function, like the one in [this thread|http://forums.oracle.com/forums/thread.jspa?messageID=3669932�].
Edited by: Frank Kulash on Aug 18, 2009 3:50 PM
To create a stand-alone function:
CREATE OR REPLACE FUNCTION to_dt
( in_txt IN VARCHAR2 -- to be converted
, in_fmt_txt IN VARCHAR2 DEFAULT 'DD-MON-YYYY' -- optional format
, in_err_dt IN DATE DEFAULT NULL
RETURN DATE
DETERMINISTIC
AS
BEGIN
-- Try to convert in_txt to a DATE. If it works, fine.
RETURN TO_DATE (in_txt, in_fmt_txt);
EXCEPTION -- If TO_DATE caused an error, then this is not a valid DATE: return in_err_dt
WHEN OTHERS
THEN
RETURN in_err_dt;
END to_dt
/To use it:
SELECT primary_key -- and/or other columns to identify the row
, demand
FROM table_x
WHERE demand IS NOT NULL
AND to_dt ( demand
, 'DDMMYY'
) IS NULL; -
How convert date with different timezone?
HI,
My problem is pretty simple. I have one Date and given another time zone (as a string), I want to have another date object with a different time zone. I used jodaTime. The code is as follows:
DateTimeZone zone = DateTimeZone.forID("US/Eastern");
DateTime parsedDateTime = DateTimeFormat.forPattern("mm/dd/yyyy").withZone(zone).parseDateTime(dstr);
System.out.println(parsedDateTime.toString());
System.out.println(parsedDateTime.toDate().toString());The output is:
2008-02-14T00:00:00.000-05:00
Thu Feb 14 11:00:00 GMT+06:00 2008
This is quite weird. As is obvious from the output, datetime stores date in the correct timezone. but when converted it to date it applies the jvm's timezone. Why is it so? And why is this time conversion mad e so difficult by providing zillions of classes and methods such as Date, Calendar etc.amishera2006 wrote:
HI,
My problem is pretty simple. I have one Date and given another time zone (as a string), I want to have another date object with a different time zone. I used jodaTime. The code is as follows:
DateTimeZone zone = DateTimeZone.forID("US/Eastern");
DateTime parsedDateTime = DateTimeFormat.forPattern("mm/dd/yyyy").withZone(zone).parseDateTime(dstr);
System.out.println(parsedDateTime.toString());
System.out.println(parsedDateTime.toDate().toString());The output is:
2008-02-14T00:00:00.000-05:00
Thu Feb 14 11:00:00 GMT+06:00 2008
This is quite weird. As is obvious from the output, datetime stores date in the correct timezone. but when converted it to date it applies the jvm's timezone. Why is it so? And why is this time conversion mad e so difficult by providing zillions of classes and methods such as Date, Calendar etc.for the first question, i can't help you
but for the second one, i guess it's for historic reasons (no defined standard at the beginning lead to a big mess, the same way as with encoding issues) -
Display BEGDA data element with dd/mm/YYYY format
Hi,
in my programm i use table HRP1002 in which there is a field BEGDA (NUM8) and i want to display it with dd/mm/YYYY, so i must obligatorily convert this field or there is a another technics ?
Regards.You can also do something like
WRITE DATE USING EDIT MASK '__.__.____'.
Hope thisll give you idea!!
<b>P.S award the points.!!! !!!</b>
Good luck
Thanks
Saquib Khan
"Some are wise and some are otherwise" -
How to add date with month after convert number to month?
How to add date with month after convert number to month?
Month Date Result
24 21/11/09 24*(21/11/09)
I want to add both the column and result should be 21/11/11
Thanks
NiharHmm,
Because, you are using YYYY for '09'.
SQL> ed
Wrote file afiedt.buf
1* select to_char(to_date('10/01/09','DD/MM/RRRR'),'DD/MM/YYYY') from dual
SQL> /
TO_CHAR(TO
10/01/2009
SQL> ed
Wrote file afiedt.buf
1* select to_char(to_date('10/01/09','DD/MM/YYYY'),'DD/MM/YYYY') from dual
SQL> /
TO_CHAR(TO
10/01/0009Or with Add_months
SQL> ed
Wrote file afiedt.buf
1* select to_char(add_months(to_date('10/01/09','DD/MM/YYYY'),36),'DD/MM/YYYY') from dual
SQL> /
TO_CHAR(AD
10/01/0012
SQL> ed
Wrote file afiedt.buf
1* select to_char(add_months(to_date('10/01/09','DD/MM/RRRR'),36),'DD/MM/YYYY') from dual
SQL> /
TO_CHAR(AD
10/01/2012-Arun -
How to convert date into dd mon yyyy format
hi all,
i have a problem in date format i am using date like below .
<%java.util.Date date = new java.util.Date();%>
i am inserting date into a table and its storing like this
insert into tablename (d_date) values (date)
and its inserting date like below
Sun Oct 19 09:05:45 GMT+03:00 2003
i want to fetch date in dd mon yyyy format.
with this format i want to make a select query.i struck with the format conversion.
how to do this.
any comments please.
any helphi all,
i understand now where i am wrong.
the below code is not working why because in my server where i am executing code the regional setting month value is in arabic.
i executed the same code in a different server where date and time jones are english its working fine.
All the problem is in regional setting and not the jsp code.
<%
String whtEverDateFormatYouWAnt = "dd MMM yy";
String str = new SimpleDateFormat(whtEverDateFormatYouWAnt).format(new SimpleDateFormat("EEE MMM dd HH:mm:ss vvv yyyy").parse("Sun Oct 19 09:05:45 GMT+03:00 2003"));
out.print(str);
%>
Thanks a lot for the excellent solution.
Thanks again. -
Converting Java.util date to XML date in format YYYY-MMM-dd
I'm using below code to convert java.util.date to XML date
public static XMLGregorianCalendar toXMLDate(Date dte) {
try {
// this may throw DatatypeConfigurationException
DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
GregorianCalendar calendar = new GregorianCalendar();
// reset all fields
calendar.clear();
Calendar parsedCalendar = Calendar.getInstance();
parsedCalendar.setTime(dte);
calendar.set( parsedCalendar.get(Calendar.YEAR ),
parsedCalendar.get(Calendar.MONTH),
parsedCalendar.get(Calendar.DATE ));
XMLGregorianCalendar xmlCalendar = datatypeFactory.newXMLGregorianCalendar( calendar );
xmlCalendar.setTimezone( DatatypeConstants.FIELD_UNDEFINED );
xmlCalendar.setFractionalSecond( null );
return xmlCalendar;
I need to get the date in the format YYYY-MMM-dd, but it returns in a format YYYY-MM-dd. Can anyone tell me how can i change the format? Thanks>
The snippet of ApplicationClient where the assignment took place and the syntax occurred were:
1. DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
2. DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
3. Date date = new Date();
4. CustomerDetail customerDetail = new CustomerDetail();
5. customerDetail.setCollectionDate(dateFormat.format(date)); //got the above syntax error
6. customerDetail.setCollectionTime(timeFormat.format(date)); //got the above syntax error
.....I am running JDK 1.6.0_10, Glassfish v2r2, MySQL 5.0, Netbeans 6.1 on Windows XP platform.The format method returns a String not a Date. Why not just store the Date as is without formatting, and format it when you want to retrieve it from the DB and display it?
m
Maybe you are looking for
-
Can I use a windows 8 installation disc for bootcamp or must I have a windows 7 disc?
Hello I'm new to this but apparently i need a windows disc to operate bootcamp and I'm not sure if I can use a windows 8 disc to install it with. Also is there a website or place I can purchase a windows 7 incase I need a windows 7 to install it with
-
When i am on the 4 step in Search Result Display options, i get errors after 2 radio buttons
I am using Oracle portal 9.0.2 version When i am on the 4 step in Search Result Display options, i get errors after 2 radio buttons Default Search Results Page This Search Portlet An unexpected error has occurred (WWS-32100) User-Defined Exception (W
-
Using tabs and the like.
The information on the Sun website wasn't too helpful when dealing with a tabbed pane. Maybe I can get the solution I want here. First of all, how would you deal with making use of the JTabbedPane class and the tabs you want to use in them? In short,
-
N8 AND NOKIA MULTIMEDIA TRANSFER
I was unable to connect my N8 with NMT. As per support webpage it is supportedby Nokia Multmedia Transfer for mac.http://europe.nokia.com/support/download-software/nokia-multimedia-transfer/download. This is what you need to do if you have problem to
-
Quick way to add multiple transitions?
Hi I producing a slideshow of about 100 still images and want to put a cross disolve between each picture. Is there a way to add all the transitions in one go? Many thanks. Adrian