Results 1 to 6 of 6

Thread: Comparing date format with java.sql.Dat

  1. #1
    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.

  2. #2
    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.

  3. #3
    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.

  4. #4
    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.

  5. #5
    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;
        )
    )

  6. #6
    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.

Similar Threads

  1. Using date format in JSP
    By KAMANA in forum Software Development
    Replies: 6
    Last Post: 29-07-2010, 10:32 AM
  2. Problem in date format
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 19-02-2010, 04:38 AM
  3. Insert date format in SQL via ASP
    By Bansi_WADIA in forum Software Development
    Replies: 4
    Last Post: 04-12-2009, 10:56 PM
  4. Changing the date format
    By Uzair in forum Customize Desktop
    Replies: 3
    Last Post: 03-04-2009, 12:44 PM
  5. whenCreated Date Format
    By settler in forum Active Directory
    Replies: 3
    Last Post: 04-01-2007, 08:44 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,894,533.30595 seconds with 17 queries