• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 506
  • Last Modified:

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
0
zolf
Asked:
zolf
  • 6
  • 4
  • 2
  • +2
4 Solutions
 
Dave BaldwinFixer of ProblemsCommented:
You would have to make a DATE column.  DATETIME column will always add the 00:00:00.

MySQL or Microsoft SQL Server?
0
 
zolfAuthor Commented:
thanks for your feedback.

I am using Microsoft SQL Server 2008
0
 
zolfAuthor Commented:
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

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Dave BaldwinFixer of ProblemsCommented:
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?
0
 
zolfAuthor Commented:
I am using hibernate to create the tables for me in the database
0
 
CEHJCommented:
this is my hibernate hbm file
Well if you used java.sql.Date instead, then that doesn't hold time info. It still might be better simply to truncate or ingore time info though
0
 
zolfAuthor Commented:
thanks for your comment.

can you please elaborate on this
It still might be better simply to truncate or ingore time info though
0
 
CEHJCommented:
It's better to have too much information (which is discardable - just don't manifest it in the presentation layer) than not enough
0
 
awking00Commented:
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)?
0
 
zolfAuthor Commented:
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();
    }
0
 
Smart_KidCommented:
Change the datatype of your column in database to DATE  (i preassume, the current datatype will be DATETIME).
0
 
CEHJCommented:
Change the datatype of your column in database to DATE  
Why would you want to lose information for a negligible saving in storage?
0
 
Smart_KidCommented:
Changing the datatype was not mentioned not to save any storage space.
But it was a possible suggestion/answer to the question.

The question is that the programmer is not interested in saving the date in database with the time info. As per the question, not even 00:00:00 should not be saved in the database. So the only option for storing just date is to change the datatype of the column.

Kindly go through the question once again.
0
 
CEHJCommented:
Kindly go through the question once again.
I don't need to ;)
0
 
zolfAuthor Commented:
Thanks
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 6
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now