First and Last date of any Month.

Advertisement
Hi Friends,
I have 2 fields in my table
FROM DATE & TO DATE
User can enter any date in these two fields, but at time of commit i want to change the FROM DATE to the first date of the Month user have entered. And for TO DATE i want to change the last date of the month.
For Example :
User Enters-
FROM DATE 12-Mar-2003
TO DATE 27-Jun-2003
I want to change these date to:
FROM DATE 01-Mar-2003
TO DATE 30-Jun-2003
How can I write a database function or procedure to control this thing.
Please help.
Best regards,
Imran Baig
Advertisement

Replay

It depends on your requirements, but I usually use TRUNC(date, 'D')
to get the first day(Sunday) of the week, because TRUNC(date, 'W')
returns the same day of the week as the first day of the month.
See http://download-west.oracle.com/docs/cd/A87860_01/doc/server.817/a85397/function.htm#80101
for more info on this.