Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > Re: First day o...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 15 Topic 3430 of 3797
Post > Topic >>

Re: First day of month, last day of month

by erik@[EMAIL PROTECTED] (Erik Jones) Apr 24, 2008 at 09:41 AM

On Apr 24, 2008, at 9:15 AM, Colin Wetherbee wrote:

> Frank Bax wrote:
>> Frank Bax wrote:
>>> Nacef LABIDI wrote:
>>>> is there a better method to retrieve all the rows with dates in=20=20
>>>> the current month.
>>>
>>> select * from mytable where extract(month from mydate) =3D=20=20
>>> extract(month from now()) and extract(year from mydate) =3D=20=20
>>> extract(year from now());
>> Sorry; I was not thinking clearly - date_trunc is better for this:
>> select * from mytable where date_trunc('month',mydate) =3D=20=20
>> date_trunc('month',now());
>
> I have some code that uses extract() for this sort of thing. 
Would=20=20
> you mind explaining how date_trunc() is better for this?
>
> Most of my extract() results end up in <select> drop-down boxes in=20=20
> HTML.


extract will pull specific date unit value out of a given date/=20
timestamp/interval.  date_trunc will "round" a given date/timestamp=20=20
down to the given unit.

extract(month from now()) -> 4

date_trunc('month', now()) -> 2008-04-01 00:00:00-05

I typically find date_trunc much more useful but I may just think that=20=
=20
because I've been writing partitioning code a lot lately.

Erik Jones

DBA | Emma=AE
erik@[EMAIL PROTECTED]
 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com




--=20
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
 




 15 Posts in Topic:
First day of month, last day of month
nacef.l@[EMAIL PROTECTED]  2008-04-24 14:59:47 
Re: First day of month, last day of month
fbax@[EMAIL PROTECTED] (  2008-04-24 09:06:25 
Re: First day of month, last day of month
fbax@[EMAIL PROTECTED] (  2008-04-24 09:16:03 
Re: First day of month, last day of month
andreas.kretschmer@[EMAIL  2008-04-24 15:15:36 
Re: First day of month, last day of month
cww@[EMAIL PROTECTED] (C  2008-04-24 10:15:23 
Re: First day of month, last day of month
erik@[EMAIL PROTECTED] (  2008-04-24 09:41:04 
Re: First day of month, last day of month
nacef.l@[EMAIL PROTECTED]  2008-04-24 16:43:40 
Re: First day of month, last day of month
scott.marlowe@[EMAIL PROT  2008-04-24 08:55:31 
Re: First day of month, last day of month
fhevia@[EMAIL PROTECTED]   2008-04-24 12:10:34 
Re: First day of month, last day of month
scott.marlowe@[EMAIL PROT  2008-04-24 08:56:50 
Re: First day of month, last day of month
erik@[EMAIL PROTECTED] (  2008-04-24 10:08:10 
Re: First day of month, last day of month
scott.marlowe@[EMAIL PROT  2008-04-24 09:16:01 
Re: First day of month, last day of month
scott.marlowe@[EMAIL PROT  2008-04-24 09:44:44 
Re: First day of month, last day of month
fhevia@[EMAIL PROTECTED]   2008-04-24 13:07:19 
Re: First day of month, last day of month
nacef.l@[EMAIL PROTECTED]  2008-04-24 18:39:06 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 9:42:37 CST 2008.