dbTalk Databases Forums  

date comparison between perl and postgres

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


Discuss date comparison between perl and postgres in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
hodges@xprt.net
 
Posts: n/a

Default date comparison between perl and postgres - 01-11-2004 , 11:18 AM






It seems that perls local::time function returns the day
of the month as 1-31 whereas postgres returns it as 01-31.

I need to compare dates

if 2004-1-12 (from perl) less than 2004-01-19 (from postgres) and its failing.

Is there a way to have perl return day of the month as
a 2 digit string or some code to automaticly pad it?
I am using

# Get current time and date
($mday,$mon,$year)=(localtime(time + (24*60*60)))[3..5];
$mon ++;
$year +=1900;
$dstr1 = "$year-$mon-$mday";

Thanks for any ideas,

Tom Hodges
hodges (AT) xprt (DOT) net

---------------------------(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
  #2  
Old   
hodges@xprt.net
 
Posts: n/a

Default Re: date comparison between perl and postgres - 01-11-2004 , 11:27 AM






To correct my self - that's month that needs to be padded
with the leading zero.

Tom

On 11 Jan 2004 at 9:18, hodges (AT) xprt (DOT) net wrote:

Quote:
It seems that perls local::time function returns the day
of the month as 1-31 whereas postgres returns it as 01-31.

I need to compare dates

if 2004-1-12 (from perl) less than 2004-01-19 (from postgres) and its failing.

Is there a way to have perl return day of the month as
a 2 digit string or some code to automaticly pad it?
I am using

# Get current time and date
($mday,$mon,$year)=(localtime(time + (24*60*60)))[3..5];
$mon ++;
$year +=1900;
$dstr1 = "$year-$mon-$mday";

Thanks for any ideas,

Tom Hodges
hodges (AT) xprt (DOT) net

---------------------------(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)



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



Reply With Quote
  #3  
Old   
Bruno Wolff III
 
Posts: n/a

Default Re: date comparison between perl and postgres - 01-12-2004 , 09:39 AM



On Sun, Jan 11, 2004 at 09:27:09 -0800,
hodges (AT) xprt (DOT) net wrote:
Quote:
Is there a way to have perl return day of the month as
a 2 digit string or some code to automaticly pad it?
I am using

# Get current time and date
($mday,$mon,$year)=(localtime(time + (24*60*60)))[3..5];
$mon ++;
$year +=1900;
$dstr1 = "$year-$mon-$mday";

Thanks for any ideas,
You could use sprintf in perl to generate the date string.

If you are actually doing the compare in postgres it might be better
to just get the time in seconds since the epoch and cast that to abstime
and then to date.
For example:
area=> select 1073921933::abstime::date;
date
------------
2004-01-12
(1 row)

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

http://www.postgresql.org/docs/faqs/FAQ.html



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.