Database IT Blogs

Articles, tips and tricks for databases
Patrick Barel I came across the need to define the first day of next month based on the current systemdate. I can do this using the following code:

add_months(to_date(’01'||to_char(sysdate,’MMYYYY’),’DDMMYYYY’),1)

But the I remembered that there was a post on the oracledeveloper.nl forum with similar date functions.

First day of the week: select trunc(sysdate,’IW’) the_date from dual;
First day of the month: select trunc(sysdate,’MM’) the_date from dual;
First day of the year: select trunc(sysdate,’IY’) the_date from dual;

Using this information the above code could be rewritten to:

add_months(trunc(SYSDATE, ‘MM’),1)

A lot shorter and I think also better, because you don’t have to do with date masks etc.

You can read more articles at http://blog.bar-solutions.com

Advertisement

Featured Links:
DreamCoder for MySQL Enterprise at USD 69.95
Powerful and easy MySQL IDE tool for Developers & DBAs.
DreamCoder for Oracle DBA at USD 99.95
The top IDE for Developers & DBAs for Oracle Databases.
DreamCoder for PostgreSQL Enterprise at USD 69.95
Powerful IDE for PostgreSQL Databases.

Tags