Home » SQL & PL/SQL » SQL & PL/SQL » First Day Of A Given Week
icon10.gif  First Day Of A Given Week [message #267703] Fri, 14 September 2007 05:45 Go to next message
CocoPop
Messages: 12
Registered: August 2007
Location: England
Junior Member
Hey Guys,

Ok I've wrote some basic code toretreive the first day of a month

to_Date('01/' || 'To_Char(SysDate, 'MM/YYYY'))

but how could i d retreive the first day of the current week?

thanks alot
Re: First Day Of A Given Week [message #267705 is a reply to message #267703] Fri, 14 September 2007 05:49 Go to previous messageGo to next message
ThomasG
Messages: 3189
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
There is the "next_day" function, which you can use to for example find the next Monday after sysdate - 7 :

SELECT Next_Day(Trunc(SYSDATE) - 7,'MON') FROM dual
Re: First Day Of A Given Week [message #267707 is a reply to message #267703] Fri, 14 September 2007 06:04 Go to previous messageGo to next message
Michel Cadot
Messages: 64102
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
SQL> select sysdate, trunc(sysdate,'WW') from dual;
SYSDATE     TRUNC(SYSDA
----------- -----------
14-SEP-2007 10-SEP-2007

1 row selected.

Regards
Michel
Re: First Day Of A Given Week [message #267708 is a reply to message #267703] Fri, 14 September 2007 06:05 Go to previous messageGo to next message
Littlefoot
Messages: 20888
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
CocoPop
Ok I've wrote some basic code ...


Why do you make things complicated?
SQL> SELECT TRUNC(SYSDATE, 'mon') first_day_of_the_month FROM dual;

FIRST_DAY_
----------
01.09.2007

SQL>
SQL> SELECT TRUNC(SYSDATE, 'ww') first_day_of_the_week FROM dual;

FIRST_DAY_
----------
10.09.2007
Re: First Day Of A Given Week [message #267717 is a reply to message #267703] Fri, 14 September 2007 06:17 Go to previous messageGo to next message
CocoPop
Messages: 12
Registered: August 2007
Location: England
Junior Member
Cool Thans All
Re: First Day Of A Given Week [message #267721 is a reply to message #267708] Fri, 14 September 2007 06:30 Go to previous messageGo to next message
ThomasG
Messages: 3189
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
Littlefoot wrote on Fri, 14 September 2007 13:05
Why do you make things complicated?


*Slaps forehead*

Because I'm not awake yet. Must get Coffee....
Re: First Day Of A Given Week [message #267729 is a reply to message #267721] Fri, 14 September 2007 06:52 Go to previous messageGo to next message
Littlefoot
Messages: 20888
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Actually, I was referring to
to_Date('01/' || 'To_Char(SysDate, 'MM/YYYY'))
(by the way, it wouldn't work at all - there's a single quote in front of TO_CHAR).

But OK, you may ./fa/1620/0/ if you wish ./fa/917/0/
Re: First Day Of A Given Week [message #267732 is a reply to message #267729] Fri, 14 September 2007 07:35 Go to previous message
joy_division
Messages: 4640
Registered: February 2005
Location: East Coast USA
Senior Member
Littlefoot wrote on Fri, 14 September 2007 07:52
Actually, I was referring to
to_Date('01/' || 'To_Char(SysDate, 'MM/YYYY'))
(by the way, it wouldn't work at all - there's a single quote in front of TO_CHAR).



And no format mask for the TO_DATE function.
Previous Topic: Need help in formatting the displayed result
Next Topic: Hard coding month and day to a year
Goto Forum:
  


Current Time: Fri Dec 02 16:26:06 CST 2016

Total time taken to generate the page: 0.10726 seconds