Solved

Save date without time

Posted on 2014-01-13
15
497 Views
Last Modified: 2014-01-16
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
Comment
Question by:zolf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
  • +2
15 Comments
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 100 total points
ID: 39775922
You would have to make a DATE column.  DATETIME column will always add the 00:00:00.

MySQL or Microsoft SQL Server?
0
 

Author Comment

by:zolf
ID: 39775930
thanks for your feedback.

I am using Microsoft SQL Server 2008
0
 

Author Comment

by:zolf
ID: 39775937
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39775948
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
 

Author Comment

by:zolf
ID: 39775991
I am using hibernate to create the tables for me in the database
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
ID: 39776157
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
 

Author Comment

by:zolf
ID: 39776186
thanks for your comment.

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

Expert Comment

by:CEHJ
ID: 39776229
It's better to have too much information (which is discardable - just don't manifest it in the presentation layer) than not enough
0
 
LVL 32

Expert Comment

by:awking00
ID: 39777535
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
 

Author Comment

by:zolf
ID: 39778366
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
 
LVL 1

Assisted Solution

by:Smart_Kid
Smart_Kid earned 300 total points
ID: 39784949
Change the datatype of your column in database to DATE  (i preassume, the current datatype will be DATETIME).
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39785058
Change the datatype of your column in database to DATE  
Why would you want to lose information for a negligible saving in storage?
0
 
LVL 1

Accepted Solution

by:
Smart_Kid earned 300 total points
ID: 39785082
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 39785112
Kindly go through the question once again.
I don't need to ;)
0
 

Author Closing Comment

by:zolf
ID: 39787633
Thanks
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question