Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7848741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:18:46+00:00 2026-06-02T18:18:46+00:00

I am using primefaces’ calendar component. I have a corresponding string in VO. While

  • 0

I am using primefaces’ calendar component. I have a corresponding string in VO. While saving in database, I need to convert the string to java.sql.date.

xhtml:

<p:calendar value="#{articlePromo.startDate}"
    id="vendorStartDateInputTxt" pattern="dd/MM/yyyy" mode="popup" showOn="button">
    <f:convertDateTime type="date"  dateStyle="short" pattern="dd/MM/yyyy" />
</p:calendar>

The startDate (String) has the value : Sat Apr 21 05:30:00 IST 2012

Java method to get sql Date

public static Date getSQLDate(String strDate) {
    java.sql.Date sqlDate = null;
    try {
        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
        java.util.Date dt = formatter.parse(strDate);
        sqlDate = new java.sql.Date(dt.getTime());
    } catch (Exception e) {
        e.printStackTrace();
    }

    return sqlDate;
}

While converting java.util.date of calendar, I used the pattern dd/MM/yyyy. But the date it got converted to is: Sat Apr 21 05:30:00 IST 2012.

  1. Is anything incorrect with f:convertDateTime tag written above.
  2. If not, how can I convert this string to sql date. Not able to understand what format should be given.

Thanks,
Shikha

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:18:49+00:00Added an answer on June 2, 2026 at 6:18 pm

    The f:convertDateTime only converts String to Object and vice versa. The Object for the p:calendar needs to be a java.util.Date (it is the value attribute). The String is the formatted date that you see in the browser!

    The Primefaces calendar automatically attaches a converter. That’s why you have the pattern attribute in p:calendar.

    So you should remove your additional f:convertDateTime as already proposed by Daniel.

    Then the conversion from java.util.Date to java.sql.Date is quite simple:

    public java.sql.Date sqlDate(java.util.Date calendarDate) {
      return new java.sql.Date(calendarDate.getTime());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Primefaces google map component. I have some markers and info windows
I am using primefaces with JSF. I need a input component that allows users
I have correctly set up a Push server using PrimeFaces p:push component (using a
I am working with MyFaces/Primefaces and I have a problem to get information using
I'm using primefaces' accordion panel. Inside the tabs i have forms which are created
I am trying to implement a Select All checkbox using primefaces component p:selectBooleanCheckbox and
I have a modal ConfirmDialog that is shown over a modal Dialog using PrimeFaces
I'm using primefaces and jstl to loop a datatable.I have a List in backing
I'm using Primefaces 3.0.RC1 and on a form I have a <p:fileUpload mode=advanced auto=true>
I am using Primefaces 3.0. I have a datatable with selectionMode single as shown

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.