Newbie Date Problems - Mailing list pgsql-novice

From John Nix
Subject Newbie Date Problems
Date
Msg-id Pine.LNX.4.44.0205091207500.24462-100000@server.sblug.org
Whole thread Raw
Responses Re: Newbie Date Problems  ("Josh Berkus" <josh@agliodbs.com>)
List pgsql-novice
I've been working with Postgres for about 2 years now.  I've never had to
do anything real advanced until now and I'm having a huge problem with
some dates.  A long time ago, I thought it would be a good idea to have
dates in 4 fields:

date = 5/2/2002
date_month = 5
date_day = 2
date_year = 2002

This was so I could view everyone in May, or everyone between the 10th and
15th, or everyone in 2002, etc... This was a huge mistake.  I have since
learned how to use date fields.  The problem is, I created a database a
while back that has over 800 records in it that uses this style of dates.
I want to convert this format to the ISO date format (YYYY-MM-DD) and I'm
having lots of problems.  I tried using this update:

update table set date_iso = (date_year || '-' || date_month || '-' ||
date_day) where table_id='838

That formats my 3 unnecesary fields to YYYY-MM-DD format.  The problem is,
the month/days are entered as 1, 2, 3, 4, etc... Not 01, 02, 03, 04, etc.
I get the error message:

Attribute 'intake_date_raw' is of type 'date' but expression is of type
'varchar' You will need to rewrite or cast the expression.

Yes, I was stupid and made the date_month, date_day, and date_year
varchars.  How can I update the database and use the current varchar
fields to create a new field formatted for dates?

-----------

Also... it looks like the search utility on the archives aren't working...

An error occured!
could not connect to server: Connection refused Is the server running on
host db.postgresql.org and accepting TCP/IP connections on port 5433?


pgsql-novice by date:

Previous
From: "G"
Date:
Subject: Altering columns without losing data
Next
From: "Josh Berkus"
Date:
Subject: Re: Newbie Date Problems