1

Sorry i am new to postgres.

Servlet gives me

UPDATED: string type in the form 07-Jul-2014.

I have inserted some date in My db column using

 to_date('1963-09-01', 'YYYY-MM-DD')//my column is of Date type

So how can i convert 07-Jul-2014 into 2014-06-07 so that i can save into my tables?

3
  • What data type is that column? "string type date" does not make sense. You also want to read this: stackoverflow.com/questions/24444971/… Commented Jul 1, 2014 at 5:37
  • @a_horse_with_no_name: sorry i have edited now Commented Jul 1, 2014 at 5:42
  • 1
    You shouldn't be converting that string in SQL. You should be parsing the string in your servlet (e.g. using SimpleDateFormat) and then use a PreparedStatement and setDate() to send the date to the database. Commented Jul 1, 2014 at 6:03

1 Answer 1

2

Try this:

to_date('07-Jul-2014', 'DD-Mon-YYYY'); Will return the result in Date format '2014-07-07'

Where '07-Jul-2014' is the string from your servlet.

Ref: http://www.postgresql.org/docs/current/static/functions-formatting.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.