-->
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.  [ 3 posts ] 
Author Message
 Post subject: Convert date time in criteria level
PostPosted: Sat Apr 28, 2012 4:28 am 
Newbie

Joined: Sat Apr 28, 2012 4:22 am
Posts: 2
Hi,
In my application i convert the date time as Server date time to User date time, because we are saving the record with server date time. While showing the records to user we are converting to user date time.

In HQL query we can convert the date time Using GMT time like this
SELECT CONVERT_TZ('2012-04-30 22:22:10','+5:30','+00:00');

But i need to done in Criteria level. How i can do for that??


Thanks
Sivabharathi S


Top
 Profile  
 
 Post subject: Re: Convert date time in criteria level
PostPosted: Sat Apr 28, 2012 2:54 pm 
Newbie

Joined: Sat Apr 28, 2012 2:48 pm
Posts: 6
hi ssivabharathi SQL Server provides a number of options you can use to format a date/time string. One of the first considerations is the actual date/time needed. The most common is the current date/time using getdate(). This provides the current date and time according to the server providing the date and time. If a universal date/time is needed, then getutcdate() should be used. To change the format of the date, you convert the requested date to a string and specify the format number corresponding to the format needed. Below is a list of formats and an example of the output:

_________________
designer sunglasses


Top
 Profile  
 
 Post subject: Re: Convert date time in criteria level
PostPosted: Sun Apr 29, 2012 9:46 am 
Newbie

Joined: Sat Apr 28, 2012 4:22 am
Posts: 2
Hi,

Thanks for your reply. I accepted we can convert in Query itself. But we are using only criteria in our application not using HQL query. One more thing i dont want to convert current date time. I want convert the datetime what we have saved before in the DB.

For example User date time 29-04-2012 10:00 AM. The server time will be 29-04-2012 10:00 PM. So the both times varying. Now user saving some data we storing the date time as 29-04-2012 10:00 PM (as server time). But while showing to user 29-04-2012 10:00 AM.

So i need convert the date time depends upon user. I know the user time zone from that i can convert through java using simpleDateFormat class. If any method in criteria itself convert timezone while fetching the record.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.