pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Frank Finner <postgresql@finner.de>
To: Gary Stainburn <gary.stainburn@ringways.co.uk>
Cc: pgsql-sql@postgresql.org
Subject: Re: working with unix timestamp
Date: Tue, 16 Mar 2004 18:56:35 +0100
Message-ID: <20040316185635.6189cb69.postgresql@finner.de> (raw)
In-Reply-To: <200403161654.18049.gary.stainburn@ringways.co.uk>
References: <200403161654.18049.gary.stainburn@ringways.co.uk>

On Tue, 16 Mar 2004 16:54:18 +0000 Gary Stainburn <gary.stainburn@ringways.co.uk> sat down, thought
long and then wrote:

> Hi folks.
> 
> I've got a last_updated field on my stock records of type timestamp.
> 
> This last_updated field I get using the perl code:
> 
> my $timestamp=(stat "$localcsv/VehicleStock.$data_suffix")[10];
> 
> How can I insert the  integer timestamp in $timestamp into my table?


I usually use somethinge like the following little function for getting an ISO timestamp. The
result is suitable for a PostgreSQL timestamp field (without special timezone).

# Subroutine for ISO-Timestamp
sub mydatetime
  {
    my ($time)=@_;	
    my ($sec,$min,$hou,$mday,$mon,$yea,$wday,$jday,$sz)=localtime($time);
    if ($sec < 10) {$sec="0".$sec;}
    if ($min < 10) {$min="0".$min;}
    if ($hou < 10) {$hou="0".$hou;}
    if ($mday < 10) {$mday="0".$mday;}
    $mon++;
    if ($mon < 10) {$mon="0".$mon;}
    $yea=$yea+1900;
    my $t=$yea."-".$mon."-".$mday." ".$hou.":".$min.":".$sec;
    return $t;
  }

Regards, Frank.



view thread (4+ messages)  latest in thread

Message-ID: <20040316185635.6189cb69.postgresql@finner.de>
Permalink:  ../20040316185635.6189cb69.postgresql@finner.de/
Also on:    postgresql.org/message-id/20040316185635.6189cb69.postgresql@finner.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: postgresql@finner.de, gary.stainburn@ringways.co.uk
  Subject: Re: working with unix timestamp
  In-Reply-To: <20040316185635.6189cb69.postgresql@finner.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox