Comparision between Date strings.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abctech
    New Member
    • Dec 2006
    • 157

    #1

    Comparision between Date strings.

    I have an Html page, user enters a Date (dd-mm-yyyy) here. There's a servlet connected in the backend for processing this submitted information, it must have a method to compare this entered date with the dates obtained from the backend table which again are retrieved as strings (dd-mm-yyyy). Can anyone suggest how to carry out comparision between these date strings?

    Eg:

    String Entered Date: "28-02-2007"
    String Backend Date: "20-01-2006"

    I need to have some function which tells me that the entered date is 1 year 1 month and 08 days ahead of the backend date.

    Right now I am using StringTokenizer (EnteredDate,"-") and StringTokenizer (BackendDate,"-") to split these two strings and get their day, month, year stored in seperate variables and then I carry out the comparision between them in if-conditions. But is there any other way to directly compare these dates?
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by abctech
    I have an Html page, user enters a Date (dd-mm-yyyy) here. There's a servlet connected in the backend for processing this submitted information, it must have a method to compare this entered date with the dates obtained from the backend table which again are retrieved as strings (dd-mm-yyyy). Can anyone suggest how to carry out comparision between these date strings?

    Eg:

    String Entered Date: "28-02-2007"
    String Backend Date: "20-01-2006"

    I need to have some function which tells me that the entered date is 1 year 1 month and 08 days ahead of the backend date.

    Right now I am using StringTokenizer (EnteredDate,"-") and StringTokenizer (BackendDate,"-") to split these two strings and get their day, month, year stored in seperate variables and then I carry out the comparision between them in if-conditions. But is there any other way to directly compare these dates?
    You can change them into date objects, or 'GregorianCalen dar' objects, and use parseDate to set your format. Check the javadocs for the date class, it should help.

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      Originally posted by sicarie
      You can change them into date objects, or 'GregorianCalen dar' objects, and use parseDate to set your format. Check the javadocs for the date class, it should help.
      Sorry - parseDate to GET the date, I think its dateFormat to set the ... well ... format.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by abctech
        I have an Html page, user enters a Date (dd-mm-yyyy) here. There's a servlet connected in the backend for processing this submitted information, it must have a method to compare this entered date with the dates obtained from the backend table which again are retrieved as strings (dd-mm-yyyy). Can anyone suggest how to carry out comparision between these date strings?

        Eg:

        String Entered Date: "28-02-2007"
        String Backend Date: "20-01-2006"

        I need to have some function which tells me that the entered date is 1 year 1 month and 08 days ahead of the backend date.

        Right now I am using StringTokenizer (EnteredDate,"-") and StringTokenizer (BackendDate,"-") to split these two strings and get their day, month, year stored in seperate variables and then I carry out the comparision between them in if-conditions. But is there any other way to directly compare these dates?
        Can create a Date object using Date.valueOf(St ring date) which requires date in the format YYYY-MM-DD, then you can use the Date methods or set it as time to a GregorianCalend ar object and use the methods there.

        Comment

        Working...