Re: How to typecast an integer into a timestamp?

From: Andy Colson <andy(at)squeakycode(dot)net>
To: bboett(at)free(dot)fr
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to typecast an integer into a timestamp?
Date: 2012-01-27 16:16:56
Message-ID: 4F22CDF8.4050905@squeakycode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/27/2012 9:44 AM, bboett(at)free(dot)fr wrote:
> Hello!
>
> again quite a stupid problem i regularly run into....
> and that i still haven't solved yet...
>
> again i used a type timestamp to keep a track of modification time, and again it gets stupid and confusing.....
>
> first of all the errors are labeled as timestamp without timezone, i only specified timestamp....
>
> the data was created as a timestamp with php-mktime, but when sending to the database postgres complains that its an int, and when i try to typecast it, (with the ::timestamp appendix to the value), that its not possible to convert an int to a timestamp (without timezone) .....
>
> so as usual i would discard the timezone datatype and alter the table to use integer instead, but this time i am wondering, since this datatype is present, there's surely a way to use it properly? but how?
>
> please enlighten me!
>
> ciao
> Bruno
>

The problem is that php mktime returns an integer. Not a date/time.
mktime returns the number of seconds since Jan 1 1970.

The best answer is to not use mktime. Find a php function that returns
a formatted string like strftime('%Y.%m.%d').

-Andy

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2012-01-27 16:17:37 Re: How to typecast an integer into a timestamp?
Previous Message Oleg Bartunov 2012-01-27 16:05:40 Re: Full Text Search, avoiding lexemes search