Avatar of Zolf
Zolf
Flag for United Arab Emirates asked on

Save date without time

Hello there,

I have this method which converts Persian date to gregoian date and saves in the mssql db. the data is now saved like this in the table col 2014-01-14 00:00:00.
How can I save the date without the time i.e. I just want to save this 2014-01-14

@SuppressWarnings("deprecation")
	public static Date jalaliToGregorian(String nowDate) {
		try{
			GWTPersianCalendar pcal1 = new GWTPersianCalendar();
			pcal1.parsePersianDate(nowDate);
			return new Date(pcal1.getTime());
			
		}
		catch (Exception e) {
			return new Date(nowDate);
		}
		
	}

Open in new window


cheers
Zolf
JavaJava EEJSP

Avatar of undefined
Last Comment
Zolf

8/22/2022 - Mon
SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Zolf

ASKER
thanks for your feedback.

I am using Microsoft SQL Server 2008
Zolf

ASKER
this is my hibernate hbm file

<property name="mfgDate" type="java.util.Date">
            <column name="mfgDate" />
        </property>
        <property name="expDate" type="java.util.Date">
            <column name="expDate" />
        </property>

Open in new window

Dave Baldwin

Here http://technet.microsoft.com/en-us/library/ms186724.aspx are the date and time datatypes available in Microsoft SQL Server.  "hibernate hbm file" means nothing to me and it does not look like it is what defines the columns in an SQL Server Database.  Is it 'your' database so you can have the columns re-defined?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Zolf

ASKER
I am using hibernate to create the tables for me in the database
SOLUTION
CEHJ

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Zolf

ASKER
thanks for your comment.

can you please elaborate on this
It still might be better simply to truncate or ingore time info though
CEHJ

It's better to have too much information (which is discardable - just don't manifest it in the presentation layer) than not enough
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
awking00

It looks like you are using the method getTime() from the GWTPersianCalendar class to return your conversion value. What datatype is that and what other methods might it have (such as getDate)?
Zolf

ASKER
by: awking00

thanks for your feedback. this is the getTime() method of GWTPersianCalendar class.that is the only method it has.

@Override
    public long getTime() {
        // TODO Remove timeZoneoffset like /*- (getTimezoneOffset()*60000) */
        return super.getTime();
    }
SOLUTION
Smart_Kid

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
CEHJ

Change the datatype of your column in database to DATE  
Why would you want to lose information for a negligible saving in storage?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Smart_Kid

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
CEHJ

Kindly go through the question once again.
I don't need to ;)
Zolf

ASKER
Thanks