Re: Get Unix timestamp from SQL timestamp through libpq

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Yan Cheng Cheok <yccheok(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Get Unix timestamp from SQL timestamp through libpq
Date: 2010-01-11 08:20:23
Message-ID: 4B4ADF47.3090409@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 11/01/2010 2:16 PM, Yan Cheng Cheok wrote:
> I know I can convert SQL timestamp to unix timestamp, using the following way.
>
> SELECT extract(epoch FROM now());
>
> Now, I have a stored procedure function, which will directly return a table row to the caller. One of the row field is "timestamp" type.
>
> In my application, I am using libpq. I wish to use libpq functions (or any c/c++ function), to convert "2010-01-11 13:10:55.283" into unix timestamp. Off course, I can create another stored procedure named
>
> SQLTimestamp2UnixTimestamp
> SELECT extract(epoch FROM $1);
>
> But I just wish to accomplish this task with a single c/c++ function call, without involving stored procedure.
>
> Any suggestion? Thanks!

Wrap strptime(...) to provide a fixed format-string. strptime is is
available on any POSIX-2001 system. It's not present on Windows, so if
you have to target win32 as well you'll need to include your own
implementation on that platform.

See "man 3 strptime"

--
Craig Ringer

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Yan Cheng Cheok 2010-01-11 08:41:32 Custom Field for a table row returned from stored procedure
Previous Message Yan Cheng Cheok 2010-01-11 08:02:40 Re: Get Unix timestamp from SQL timestamp through libpq