dbTalk Databases Forums  

Function to convert bigint to date

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Function to convert bigint to date in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Pradeepkumar, Pyatalo
 
Posts: n/a

Default Function to convert bigint to date - 10-21-2004 , 10:47 AM







Hi all,
For my application we are storing the date information by casting it into
BIGINT using the following
extract('epoch' from current_timestamp)::bigint

But how do I convert the BIGINT to the date format 'dd mm yyyy' a function
similar to to_date(text,text)
Is there any function to do this conversion.

Thanks in advance

With Best Regards,
Pradeep Kumar P.J



Reply With Quote
  #2  
Old   
Steven Klassen
 
Posts: n/a

Default Re: Function to convert bigint to date - 10-21-2004 , 12:17 PM






* Pradeepkumar, Pyatalo (IE10) <Pradeepkumar.Pyatalo (AT) honeywell (DOT) com> [2004-10-21 07:47:21 -0700]:

Quote:
But how do I convert the BIGINT to the date format 'dd mm yyyy' a
function similar to to_date(text,text)
This reply from Richard Huxton should do the trick:

http://archives.postgresql.org/pgsql...7/msg00397.php

--
Steven Klassen - Lead Programmer
Command Prompt, Inc. - http://www.commandprompt.com/
PostgreSQL Replication & Support Services, (503) 667-4564

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings



Reply With Quote
  #3  
Old   
Pradeepkumar, Pyatalo
 
Posts: n/a

Default Re: Function to convert bigint to date - 10-25-2004 , 05:23 AM




Hi,
But from the result I need to display only the date and not the time. Should
I use extract() function to get the day, month and year seperately and then
form the date format, or is there any other way to extract only the date
part from the timestamp.

Regs,
Pradeep




-----Original Message-----
From: pgsql-novice-owner (AT) postgresql (DOT) org
[mailtogsql-novice-owner (AT) postgresql (DOT) org] On Behalf Of Steven Klassen
Sent: Thursday, October 21, 2004 9:48 PM
To: Pradeepkumar, Pyatalo (IE10)
Cc: pgsql-novice (AT) postgresql (DOT) org
Subject: Re: [NOVICE] Function to convert bigint to date

* Pradeepkumar, Pyatalo (IE10) <Pradeepkumar.Pyatalo (AT) honeywell (DOT) com>
[2004-10-21 07:47:21 -0700]:

Quote:
But how do I convert the BIGINT to the date format 'dd mm yyyy' a
function similar to to_date(text,text)
This reply from Richard Huxton should do the trick:

http://archives.postgresql.org/pgsql...7/msg00397.php

--
Steven Klassen - Lead Programmer
Command Prompt, Inc. - http://www.commandprompt.com/ PostgreSQL Replication
& Support Services, (503) 667-4564

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)



Reply With Quote
  #4  
Old   
Pradeepkumar, Pyatalo
 
Posts: n/a

Default Re: Function to convert bigint to date - 10-25-2004 , 11:38 PM





Hi,
But from the result I need to display only the date and not the time. Should
I use extract() function to get the day, month and year seperately and then
form the date format, or is there any other way to extract only the date
part from the timestamp.

Regs,
Pradeep




-----Original Message-----
From: pgsql-novice-owner (AT) postgresql (DOT) org
[mailtogsql-novice-owner (AT) postgresql (DOT) org] On Behalf Of Steven Klassen
Sent: Thursday, October 21, 2004 9:48 PM
To: Pradeepkumar, Pyatalo (IE10)
Cc: pgsql-novice (AT) postgresql (DOT) org
Subject: Re: [NOVICE] Function to convert bigint to date

* Pradeepkumar, Pyatalo (IE10) <Pradeepkumar.Pyatalo (AT) honeywell (DOT) com>
[2004-10-21 07:47:21 -0700]:

Quote:
But how do I convert the BIGINT to the date format 'dd mm yyyy' a
function similar to to_date(text,text)
This reply from Richard Huxton should do the trick:

http://archives.postgresql.org/pgsql...7/msg00397.php

--
Steven Klassen - Lead Programmer
Command Prompt, Inc. - http://www.commandprompt.com/ PostgreSQL Replication
& Support Services, (503) 667-4564

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend



Reply With Quote
  #5  
Old   
Steven Klassen
 
Posts: n/a

Default Re: Function to convert bigint to date - 10-25-2004 , 11:46 PM



* Pradeepkumar, Pyatalo (IE10) <Pradeepkumar.Pyatalo (AT) honeywell (DOT) com> [2004-10-25 02:23:19 -0700]:

Quote:
But from the result I need to display only the date and not the
time. Should I use extract() function to get the day, month and year
seperately and then form the date format, or is there any other way
to extract only the date part from the timestamp.
You can cast a timestamp to a date. You really need to give these
things a try yourself. You'd be surprised what you can figure out
through trial and error.

xinu=> select now()::timestamp;
now
----------------------------
2004-10-25 23:45:38.939148
(1 row)

xinu=> select (now()::timestamp)::date;
now
------------
2004-10-25
(1 row)

--
Steven Klassen - Lead Programmer
Command Prompt, Inc. - http://www.commandprompt.com/
PostgreSQL Replication & Support Services, (503) 667-4564

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.