Thread: Converting POSTGRESQL timestamp to UNIX timestamp

Converting POSTGRESQL timestamp to UNIX timestamp

From
Richie
Date:
Hi

I have a field of type timestamp in my database but when I retrieve it I
want to convert it to its unix timetamp value because I need to compare 2
tables by their timestamp value.

Any ideas how to convert PostgreSQL timestamp to Unix timestamp???

Thanks

Richie

=========================================================
Richie Duggan
Computer Science IV
University College Cork
Eamil : dugganr@student.cs.ucc.ie   richie_dug@yahoo.com
Homepage : http://student.cs.ucc.ie/01/dugganr/index.html


Re: Converting POSTGRESQL timestamp to UNIX timestamp

From
"Dan Wilson"
Date:
http://www.php.net/manual/en/function.strtotime.php


: Hi
:
: I have a field of type timestamp in my database but when I retrieve it I
: want to convert it to its unix timetamp value because I need to compare 2
: tables by their timestamp value.
:
: Any ideas how to convert PostgreSQL timestamp to Unix timestamp???
:
: Thanks
:
: Richie



Re: Converting POSTGRESQL timestamp to UNIX timestamp

From
Grant
Date:
select date_part('epoch', timestamp(topics.date_added)) from table;

On Thu, 22 Mar 2001, Richie wrote:

> Hi
>
> I have a field of type timestamp in my database but when I retrieve it I
> want to convert it to its unix timetamp value because I need to compare 2
> tables by their timestamp value.
>
> Any ideas how to convert PostgreSQL timestamp to Unix timestamp???
>
> Thanks
>
> Richie
>
> =========================================================
> Richie Duggan
> Computer Science IV
> University College Cork
> Eamil : dugganr@student.cs.ucc.ie   richie_dug@yahoo.com
> Homepage : http://student.cs.ucc.ie/01/dugganr/index.html
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster




Re: data type casting to numbers with intval() or doubleval()

From
Wesley Leonard
Date:
I think a regex would be most appropriate here:

<?php

$my_string = "mmm444";

$my_integer = intval(eregi_replace("[a-z]", "", $my_string));

print $my_integer;

?>

This removes all letters and takes the int value.  In perl you can remove
everything that's NOT a digit but I didn't figure that out in PHP yet...  this
should do for now.

l8er

imago wrote:
>
> I am having a problem with the intval() function
>
> I am using it to take string data and extract the number it would
> represent if only numeric.
>
> $my_integer = intval($my_string)
>
> when the sting is numbers followed by letters -
> $my_string = 4444mmm
> $my_integer = 4444
> it works as expected
>
> but when letters are followed by numbers
> $my_string = mmm4444
> $my_integer = 0
>
> Same problem with doubleval()
>
> What am I missing????  how do I drop the non-numeric parts of a
> string?
>
> imago

--

Wesley Leonard
marshall@pacdemon.org

http://www.pacdemon.org
"...I want Linux to be on the cutting edge, and even a bit past the edge,
because what's past the edge today is what's on your desktop tomorrow."
    --Linus Torvalds

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html




data type casting to numbers with intval() or doubleval()

From
"imago"
Date:
I am having a problem with the intval() function

I am using it to take string data and extract the number it would
represent if only numeric.

$my_integer = intval($my_string)

when the sting is numbers followed by letters -
$my_string = 4444mmm
$my_integer = 4444
it works as expected

but when letters are followed by numbers
$my_string = mmm4444
$my_integer = 0

Same problem with doubleval()

What am I missing????  how do I drop the non-numeric parts of a
string?

imago


Re: Converting POSTGRESQL timestamp to UNIX timestamp

From
Grant
Date:
select date_part('epoch', timestamp(topics.date_added)) from table;

On Thu, 22 Mar 2001, Richie wrote:

> Hi
>
> I have a field of type timestamp in my database but when I retrieve it I
> want to convert it to its unix timetamp value because I need to compare 2
> tables by their timestamp value.
>
> Any ideas how to convert PostgreSQL timestamp to Unix timestamp???
>
> Thanks
>
> Richie
>
> =========================================================
> Richie Duggan
> Computer Science IV
> University College Cork
> Eamil : dugganr@student.cs.ucc.ie   richie_dug@yahoo.com
> Homepage : http://student.cs.ucc.ie/01/dugganr/index.html
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster




Re: data type casting to numbers with intval() or doubleval()

From
Wesley Leonard
Date:
I think a regex would be most appropriate here:

<?php

$my_string = "mmm444";

$my_integer = intval(eregi_replace("[a-z]", "", $my_string));

print $my_integer;

?>

This removes all letters and takes the int value.  In perl you can remove
everything that's NOT a digit but I didn't figure that out in PHP yet...  this
should do for now.

l8er

imago wrote:
>
> I am having a problem with the intval() function
>
> I am using it to take string data and extract the number it would
> represent if only numeric.
>
> $my_integer = intval($my_string)
>
> when the sting is numbers followed by letters -
> $my_string = 4444mmm
> $my_integer = 4444
> it works as expected
>
> but when letters are followed by numbers
> $my_string = mmm4444
> $my_integer = 0
>
> Same problem with doubleval()
>
> What am I missing????  how do I drop the non-numeric parts of a
> string?
>
> imago

--

Wesley Leonard
marshall@pacdemon.org

http://www.pacdemon.org
"...I want Linux to be on the cutting edge, and even a bit past the edge,
because what's past the edge today is what's on your desktop tomorrow."
    --Linus Torvalds

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html




Re: Re: data type casting to numbers with intval() or doubleval()

From
"Papp Gyozo"
Date:
> I think a regex would be most appropriate here:
>
> <?php
>
> $my_string = "mmm444";
>
> $my_integer = intval(eregi_replace("[a-z]", "", $my_string));
>
> print $my_integer;
>
> ?>
>
> This removes all letters and takes the int value.  In perl you can remove
> everything that's NOT a digit but I didn't figure that out in PHP yet...  this
> should do for now.

you're thinking of something like:

 $my_integer = intval(preg_replace('!\D+!', '', $my_string));

aren't you?

PCRE regular expression finctions are PERL compatible reg. functions
using PCRE library.