Newbie timestamp question

Lists: pgsql-general
From: "Robin 'Sparky' Kopetzky" <sparkyk(at)blackmesa-isp(dot)net>
To: "PostgreSQL General" <pgsql-general(at)postgresql(dot)org>
Subject: Newbie timestamp question
Date: 2004-03-17 18:52:19
Message-ID: BAENJGGPMHPCLAKAEPHAEENMCCAA.sparkyk@blackmesa-isp.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Good Morning!!

I'm repairing a series of scripts in PHP that use the 'datetime' of MySQL
and converting them to Postgres. Question is this: The datetime format used
in the script is 'YYYYMMDDHHMMSS' as a text string. Do I have to convert
this to the format shown in the Postgres manual: '1999-01-08 04:05:06' for
Postgres to accept the value or can I just pass an integer as 19990108040506
for the timestamp?

Thanks in advance.

Robin Kopetzky
Black Mesa Computers/Internet Services
Grants, NM


From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: "Robin 'Sparky' Kopetzky" <sparkyk(at)blackmesa-isp(dot)net>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Newbie timestamp question
Date: 2004-03-17 19:00:55
Message-ID: Pine.LNX.4.33.0403171200140.11180-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Wed, 17 Mar 2004, Robin 'Sparky' Kopetzky wrote:

> Good Morning!!
>
> I'm repairing a series of scripts in PHP that use the 'datetime' of MySQL
> and converting them to Postgres. Question is this: The datetime format used
> in the script is 'YYYYMMDDHHMMSS' as a text string. Do I have to convert
> this to the format shown in the Postgres manual: '1999-01-08 04:05:06' for
> Postgres to accept the value or can I just pass an integer as 19990108040506
> for the timestamp?

You can just seperate the date part from the time part with a space and it
will work:

postgres=# create table test (dt timestamp);
CREATE TABLE
postgres=# insert into test values ('20020202121410');
ERROR: invalid input syntax for type timestamp: "20020202121410"
postgres=# insert into test values ('20020202 121410');
INSERT 20297173 1
postgres=# select * from test;
dt
---------------------
2002-02-02 12:14:10


From: Richard Huxton <dev(at)archonet(dot)com>
To: "Robin 'Sparky' Kopetzky" <sparkyk(at)blackmesa-isp(dot)net>, "PostgreSQL General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Newbie timestamp question
Date: 2004-03-17 19:09:20
Message-ID: 200403171909.20207.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Wednesday 17 March 2004 18:52, Robin 'Sparky' Kopetzky wrote:
> Good Morning!!
>
> I'm repairing a series of scripts in PHP that use the 'datetime' of MySQL
> and converting them to Postgres. Question is this: The datetime format used
> in the script is 'YYYYMMDDHHMMSS' as a text string. Do I have to convert
> this to the format shown in the Postgres manual: '1999-01-08 04:05:06' for
> Postgres to accept the value or can I just pass an integer as
> 19990108040506 for the timestamp?

You need to pass it a valid timestamp, either in ISO format as you show, or
European/US/... standards (depending on your settings). There's a full list
of formats in the data-types section of the manuals.

--
Richard Huxton
Archonet Ltd


From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Robin 'Sparky' Kopetzky <sparkyk(at)blackmesa-isp(dot)net>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Newbie timestamp question
Date: 2004-03-17 19:19:54
Message-ID: 20040317191954.GA16639@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Wed, Mar 17, 2004 at 11:52:19 -0700,
Robin 'Sparky' Kopetzky <sparkyk(at)blackmesa-isp(dot)net> wrote:
> Good Morning!!
>
> I'm repairing a series of scripts in PHP that use the 'datetime' of MySQL
> and converting them to Postgres. Question is this: The datetime format used
> in the script is 'YYYYMMDDHHMMSS' as a text string. Do I have to convert
> this to the format shown in the Postgres manual: '1999-01-08 04:05:06' for
> Postgres to accept the value or can I just pass an integer as 19990108040506
> for the timestamp?

You certainly couldn't have it as an integer. Even as type unknown
(which you get by quoting the constant) it doesn't work. You can use
to_timestamp to convert the string. For example:
bruno=> select to_timestamp('19990108040506', 'YYYYMMDDHH24MISS');
to_timestamp
------------------------
1999-01-08 04:05:06+00
(1 row)


From: "Robin 'Sparky' Kopetzky" <sparkyk(at)blackmesa-isp(dot)net>
To: "PostgreSQL General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Newbie timestamp question
Date: 2004-03-17 21:49:14
Message-ID: BAENJGGPMHPCLAKAEPHAEEOECCAA.sparkyk@blackmesa-isp.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Thank you for all your help.

I built two simple functions (extract_timestamp, build_timestamp) to tear
apart a timestamp and put it back together to make the job easier.

Thanks again!

'Sparky'