-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: how to change the date format--plz help
PostPosted: Mon Mar 02, 2009 3:10 am 
Beginner
Beginner

Joined: Fri Feb 13, 2009 5:27 am
Posts: 36
Location: India
Hi,
Can i change the format of the date type ...


like when i use type="date" it generate the data type as date and when i save a particular date in my appilcation{new Date()},it save like 23-02-2009




I want the format like 23/02/2009

or 23 feb 2009


Can we change it?
if yes then reply plz...\if no then also reply plz..wkth d reason...thank u in advance

_________________
parag


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 02, 2009 7:06 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Which date format do you want to change? You mean the format in which the date field is stored in the DB? I dont think that can be changed. In DB dates are stored in its own internal format. For eg the number of milliseconds since the standard base time January 1, 1970, 00:00:00 GMT.

If what you mean is the format of the retrieved date then you can set that format by using:
alter session set nls_date_format='DD/MM/YYYY HH24:MI:SS'

Please tell exactly what you want to do and why you want that. Then may be we can figure out the solution.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 02, 2009 9:02 am 
Beginner
Beginner

Joined: Fri Feb 13, 2009 5:27 am
Posts: 36
Location: India
hi litty,

actually the code is like this


<property name="dateOfExam" column="EXAM_DATE" type="date"/>


it store in database as

+------------
| EXAM_DATE
+------------
| 2009-03-02
+------------


i wantb

Exam_date as 2009/03/02 in database

n thank u very much

_________________
parag


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 02, 2009 9:09 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
You said tht "it store in database as 2009-03-02". But this is not true. Coz as I said earlier the fields like date and timestamp are not stored as any formated String, but as numbers. Now when you query the DB you might be seeing the date field in the format YYYY-DD-MM. This is controlled by the NLS properties of your session which you can set by:
alter session set nls_date_format='DD/MM/YYYY HH24:MI:SS'

Do let me know if you are not clear.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 03, 2009 1:03 am 
Beginner
Beginner

Joined: Fri Feb 13, 2009 5:27 am
Posts: 36
Location: India
hi litty,
can u tell me the exact procedure to set nls_date_format='DD/MM/YYYY HH24:MI:SS' in session...i m beginner ,i dont know how to set these properties..n thanks

_________________
parag


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 03, 2009 2:13 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Changing the date time format is different in different DB. In Oracle you can use Alter Session statement, mssql gets the date format from the windows date-time format settings etc.

For oracle using hibernate you can execute this sql by:
Code:
String sql = "alter session set nls_date_format='MM/DD/YYYY HH24:MI:SS'";
session.createSQLQuery(sql).executeUpdate();


But I don't think this would be of any help to you. Coz what you get from hibernate for a datetype field is a java.util.Date object and the format of the date will be dependent on Locale. But you can use a java.text.SimpleDateFormat to format that Date object.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 03, 2009 2:22 am 
Newbie

Joined: Tue Mar 03, 2009 2:15 am
Posts: 2
When you set display configuration options for dates, times, and numbers in the operating system, these settings affect the Date dialog box and other operating system windows. The Windows software you use also adopts those settings as you enter dates, times, and numbers (including currency) in your documents. This articles describes how to change the way Windows XP displays dates, times, currency values, and numbers.

_________________
Corporate clothing
Tee Shirt printing


Last edited by alyssa on Wed Mar 04, 2009 8:19 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 03, 2009 2:25 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
But I don't think changing the OS date format for an application sake is a good approach. Well java has a good Locale api for handling that.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 03, 2009 2:33 am 
Newbie

Joined: Fri Jan 16, 2009 4:30 am
Posts: 1
Location: Indonesia
I think its application code responsibility to format how date type is displayed. There are thousands API for this purpose available. For example: org.apache.commons.lang.time.DateFormatUtils(date, "yyyy/MM/dd") ;


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.