pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
What day is it - when it isn't NOW()?
4+ messages / 3 participants
[nested] [flat]

* What day is it - when it isn't NOW()?
@ 2003-08-01 18:27 tomg@sqlclinic.net
  2003-08-01 18:28 ` Re: What day is it - when it isn't NOW()? Rod Taylor <rbt@rbt.ca>
  2003-08-01 18:28 ` Re: What day is it - when it isn't NOW()? Josh Berkus <josh@agliodbs.com>
  0 siblings, 2 replies; 4+ messages in thread

From: tomg@sqlclinic.net @ 2003-08-01 18:27 UTC (permalink / raw)
  To: pgsql-sql

Hi,

SELECT to_char(now(), 'Day');  returns Friday as I'd hoped.
But how do I return the day of the week for a specific date other
than now()?  I'm looking for something along the lines of:
SELECT to_char('2003-08-04', 'Day') without much success.

Can anyone point me to the right function/combination of functions
to achieve this?

Thanks!

-----------------------------------------------------------------------
Thomas Good                                  e-mail: tomg@sqlclinic.net
Programmer/Analyst                           phone:   (+1) 718.818.5528
Residential Services                         fax:     (+1) 718.818.5056
Behavioral Health Services, SVCMC-NY         mobile:  (+1) 917.282.7359

// Welches ist das groessere Verbrechen?
// Massenvernichtungswaffen besitzen oder sie erfinden?





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: What day is it - when it isn't NOW()?
  2003-08-01 18:27 What day is it - when it isn't NOW()? tomg@sqlclinic.net
@ 2003-08-01 18:28 ` Rod Taylor <rbt@rbt.ca>
  1 sibling, 0 replies; 4+ messages in thread

From: Rod Taylor @ 2003-08-01 18:28 UTC (permalink / raw)
  To: tomg@sqlclinic.net; +Cc: pgsql-sql

'2003-08-04' is ambiguous.  It could be a text string, a date, something
else.  So cast it.

SELECT to_char('2003-08-04'::date, 'Day');

> SELECT to_char(now(), 'Day');  returns Friday as I'd hoped.
> But how do I return the day of the week for a specific date other
> than now()?  I'm looking for something along the lines of:
> SELECT to_char('2003-08-04', 'Day') without much success.
> 
> Can anyone point me to the right function/combination of functions
> to achieve this?
> 
> Thanks!
> 
> -----------------------------------------------------------------------
> Thomas Good                                  e-mail: tomg@sqlclinic.net
> Programmer/Analyst                           phone:   (+1) 718.818.5528
> Residential Services                         fax:     (+1) 718.818.5056
> Behavioral Health Services, SVCMC-NY         mobile:  (+1) 917.282.7359
> 
> // Welches ist das groessere Verbrechen?
> // Massenvernichtungswaffen besitzen oder sie erfinden?
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
> 

Attachments:

  signature.asc (application/pgp-signature, 186B) download

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: What day is it - when it isn't NOW()?
  2003-08-01 18:27 What day is it - when it isn't NOW()? tomg@sqlclinic.net
@ 2003-08-01 18:28 ` Josh Berkus <josh@agliodbs.com>
  2003-08-01 18:53   ` Re: What day is it - when it isn't NOW()? tomg@sqlclinic.net
  1 sibling, 1 reply; 4+ messages in thread

From: Josh Berkus @ 2003-08-01 18:28 UTC (permalink / raw)
  To: pgsql-sql

Thomas,

> SELECT to_char(now(), 'Day');  returns Friday as I'd hoped.
> But how do I return the day of the week for a specific date other
> than now()?  I'm looking for something along the lines of:
> SELECT to_char('2003-08-04', 'Day') without much success.
>
> Can anyone point me to the right function/combination of functions
> to achieve this?

Well, you could try the online docs under "Functions and operators" <grin>.

Two possibilities:

SELECT to_char('2003-08-04'::TIMESTAMP, 'Day') should make the to_char version 
work for you.

Alternately, SELECT EXTRACT(dow FROM '2003-08-04') will give you a numerical 
(0-6) day of the week.

-- 
Josh Berkus
Aglio Database Solutions
San Francisco



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: What day is it - when it isn't NOW()?
  2003-08-01 18:27 What day is it - when it isn't NOW()? tomg@sqlclinic.net
  2003-08-01 18:28 ` Re: What day is it - when it isn't NOW()? Josh Berkus <josh@agliodbs.com>
@ 2003-08-01 18:53   ` tomg@sqlclinic.net
  0 siblings, 0 replies; 4+ messages in thread

From: tomg@sqlclinic.net @ 2003-08-01 18:53 UTC (permalink / raw)
  To: Josh Berkus <josh@agliodbs.com>; +Cc: pgsql-sql

On Fri, 1 Aug 2003, Josh Berkus wrote:

> Thomas,
>
> > than now()?  I'm looking for something along the lines of:
> > SELECT to_char('2003-08-04', 'Day') without much success.
> >
>
> Well, you could try the online docs under "Functions and operators" <grin>.

Hey Josh, how goes...yeah I bumbled around date/time functions for awhile but
couldn't find the right syntax...maybe I need new glasses? ;-)

> Alternately, SELECT EXTRACT(dow FROM '2003-08-04') will give you a numerical
> (0-6) day of the week.

I tried this but I don't need an integer returned so I went with the
to_char() approach.  Thanks for tip - and thanks to Rod as well.


On 1 Aug 2003, Rod Taylor wrote:

>
> SELECT to_char('2003-08-04'::date, 'Day');
>

This is what I went for as it is the closest to the MySQL/Oracle syntax
I use for the same purpose, particularly Oracle:

$query = qq |SELECT DATE_FORMAT('$start_date', '%W')| if ($dbtype eq 'mysql');
$query = qq |SELECT TO_CHAR('start_date'::date, 'Day') if ($dbtype eq 'postgres');
$query = qq |SELECT TO_CHAR(TO_DATE('$start_date'), 'Day') FROM DUAL| if ($dbtype eq 'oracle');

Thanks again fellas - have a nice weekend!

Cheers

-----------------------------------------------------------------------
Thomas Good                                  e-mail: tomg@sqlclinic.net
Programmer/Analyst                           phone:   (+1) 718.818.5528
Residential Services                         fax:     (+1) 718.818.5056
Behavioral Health Services, SVCMC-NY         mobile:  (+1) 917.282.7359

// Welches ist das groessere Verbrechen?
// Massenvernichtungswaffen besitzen oder sie erfinden?





^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2003-08-01 18:53 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-08-01 18:27 What day is it - when it isn't NOW()? tomg@sqlclinic.net
2003-08-01 18:28 ` Rod Taylor <rbt@rbt.ca>
2003-08-01 18:28 ` Josh Berkus <josh@agliodbs.com>
2003-08-01 18:53   ` tomg@sqlclinic.net

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox