More time manipulation..

Started by Williams, Travis L, NPONSover 23 years ago5 messagesgeneral
Jump to latest

If I do "select Current_Date".. I get something like:
2002-11-25
if I do "select Current_Date + interval '7 days'; I get:
2002-11-25 00:00:00-06
is there any way to get it to only return the parts I'm passing it (all I want is the date).. I know I can do date_part and pull out the individual parts and put it back together.. but it looks like I'm missing something..

Thanks,

Travis

#2Frank Bax
fbax@sympatico.ca
In reply to: Williams, Travis L, NPONS (#1)
Re: More time manipulation..

select (Current_Date + interval '7 days')::date

At 02:07 PM 11/18/02, Williams, Travis L, NPONS wrote:

Show quoted text

If I do "select Current_Date".. I get something like:
2002-11-25
if I do "select Current_Date + interval '7 days'; I get:
2002-11-25 00:00:00-06
is there any way to get it to only return the parts I'm passing it (all I
want is the date).. I know I can do date_part and pull out the individual
parts and put it back together.. but it looks like I'm missing something..

Thanks,

Travis

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

#3Gregory Seidman
gss+pg@cs.brown.edu
In reply to: Williams, Travis L, NPONS (#1)
Re: More time manipulation..

Williams, Travis L, NPONS sez:
} If I do "select Current_Date".. I get something like:
} 2002-11-25
} if I do "select Current_Date + interval '7 days'; I get:
} 2002-11-25 00:00:00-06
} is there any way to get it to only return the parts I'm passing it
} (all I want is the date).. I know I can do date_part and pull out the
} individual parts and put it back together.. but it looks like I'm
} missing something..

The short answer is to use date_part and like it.

The longer answer is that the addition (+) operator is not defined on a
date and an interval, but since it is defined on a timestamp and an
interval, and a date is castable to a timestamp, PostgreSQL helpfully
casts the date to a timestamp, performs the addition, and returns a
timestamp. What you are getting back is a timestamp because it's the
result of adding an interval to a timestamp.

} Thanks,
} Travis
--Greg

In reply to: Gregory Seidman (#3)
Re: More time manipulation..

Thank you very much!!.. is there any where I can find more information
on Time Manipulation.. I looked under the idocs.. but they're really
lacking..

Travis

-----Original Message-----
From: Frank Bax [mailto:fbax@sympatico.ca]
Sent: Monday, November 18, 2002 1:17 PM
To: Williams, Travis L, NPONS; pgsql-general@postgresql.org
Subject: Re: [GENERAL] More time manipulation..

select (Current_Date + interval '7 days')::date

At 02:07 PM 11/18/02, Williams, Travis L, NPONS wrote:

If I do "select Current_Date".. I get something like:
2002-11-25
if I do "select Current_Date + interval '7 days'; I get:
2002-11-25 00:00:00-06
is there any way to get it to only return the parts I'm passing it (all

I

want is the date).. I know I can do date_part and pull out the

individual

parts and put it back together.. but it looks like I'm missing

something..

Thanks,

Travis

---------------------------(end of

broadcast)---------------------------

TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to

majordomo@postgresql.org)

#5Bruno Wolff III
bruno@wolff.to
In reply to: Gregory Seidman (#3)
Re: More time manipulation..

} if I do "select Current_Date + interval '7 days'; I get:
} 2002-11-25 00:00:00-06

Another option is to use:
select current_date + 7;
As long as you are moving by days (not months, years, hours etc.), this
is probably the simplest solution.