Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Comparing date format with java.sql.Dat

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 22-07-2010
Member
 
Join Date: Sep 2009
Posts: 131
Comparing date format with java.sql.Dat
  

Hello,
Wish I could compare a date recovered on a database, so java.sql.Date format, with the date of the day. I have found many ways to get a date format from java.sql.Date to java.util.Date date format. However, to compare two dates, I have found the methods presented in class java.util.Date. My problem is to succeed to convert a date format java.sql.Date java.util.Date order to use the proposed methods of comparison.

Reply With Quote
  #2  
Old 22-07-2010
Member
 
Join Date: Nov 2009
Posts: 333
Re: Comparing date format with java.sql.Dat

Bin class inherits from the class java.sql.Date java.util.Date There's no problem then the method compareTo() is applied to an object of type java.sql.Date. It should perhaps just be careful to cast properly compare two objects.
Reply With Quote
  #3  
Old 22-07-2010
Member
 
Join Date: Jan 2010
Posts: 119
Re: Comparing date format with java.sql.Dat

I must get a date for a database and compared to the current day's date for use:
Code:
Date td = new Date ();
and the date of the database in an application that gives the date the form YEAR-MONTH-DAY. How can I compare the two please or retrieve the month of the current date, day and year because getYear () for example does not work. Any more help regarding this topic is appreciated. Thank you.
Reply With Quote
  #4  
Old 22-07-2010
Member
 
Join Date: Jan 2010
Posts: 119
Re: Comparing date format with java.sql.Dat

I tested a small but doubts persist, for the current date no problem:
Code:
private static Date dt = Calendar.getInstance ();
For the month is what the syntax is correct:
Code:
private static int cal = Calendar.getInstance (). MONTH;
I do not know what exactly to do, any help will be great. Thank you.
Reply With Quote
  #5  
Old 29-07-2010
Member
 
Join Date: Dec 2009
Posts: 204
Re: Comparing date format with java.sql.Dat

Check out the following code
Code:
public abstract class DateParser
(
    / ** The formatter ** /
    private static DateFormat frm = init();
 
    / ** Initialize the formatter ** /
    private static DateFormat init()
    ( DateFormat frm = new SimpleDateFormat("yyyy-MM -dd HH: mm: ss "); frm.setLenient(false);
      return frm;
    )
    
    / ** Convert the string into Date object * @ param String txtDate frm yyyy-mm-dd hh: mm: ss to be converted * @ return Date corresponding (null if input error) ** /
    public static Date convert(String txtDate)
    (
                
        p = ParsePosition new ParsePosition(0); Date date = frm.parse(txtDate, p);
        if( p.getErrorIndex() ! = -1 | | p.getIndex() ! = txtDate.length() )  return null,
 
        return day;
    )
)
Reply With Quote
  #6  
Old 02-08-2010
Member
 
Join Date: Nov 2009
Posts: 359
Re: Comparing date format with java.sql.Dat

As part of a web application, I collect, among other-, two dates with time. To ensure that these dates can be inserted into a database, a set of JavaScript requires the user to fill a date and time in the form yyyy-mm-dd hh: mm: ss.
However, before inserting the data into the database, I need to make sure they check a rule of priority. A date must be earlier than the date B.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Comparing date format with java.sql.Dat"
Thread Thread Starter Forum Replies Last Post
Using date format in JSP KAMANA Software Development 6 29-07-2010 10:32 AM
Problem in date format Vodka Software Development 5 19-02-2010 04:38 AM
Insert date format in SQL via ASP Bansi_WADIA Software Development 4 04-12-2009 10:56 PM
Changing the date format Uzair Customize Desktop 3 03-04-2009 12:44 PM
whenCreated Date Format settler Active Directory 3 04-01-2007 08:44 AM


All times are GMT +5.5. The time now is 01:46 PM.