|
This is how I compute a few useful dates in SQL Server:
So, you can see we have several different, useful dates loaded into variables. Even if I just need @fdcm (first day, current month), I usually just toss the entire block of code into my proc. I'm going to want to do similar date calcs in Oracle, too. If you've got similar date calcs in Oracle, please post them, as I'd like to to learn how Oracle developers typically address similar problems. And if you're an Oracle developer searching for a way to do similar date calcs in SQL Server, well, here you go. If you want to see date examples other than today, just uncomment the second set of @today and fill in any date you like.
(comments are locked)
|
|
Thanks, that really gives me a chance to demonstrate why I hate T-SQL date handling. The equivalent in PL/SQL is:
In practice, I don't usually end up using variables like these in Oracle, since the date handling is so simple to use (at least once you've got it by heart that there are 1440 minutes, or 86400 seconds, in a day, so expressions like sysdate+15/1440 are common). "Thanks, that really gives me a chance to demonstrate why I hate T-SQL date handling" - Glad I was able to add something to your day. The TRUNC function is more useful than I realized. Thanks.
Feb 12 '10 at 11:42 AM
KillerDBA
On reflection, while The Oracle Way is reasonably easy, I find it dissatisfying. I'm a big fan of rich datatypes and datetime/date/time/interval are superior ways do deal with date calculations. This isn't intended as praise for SQL Server, mind you, but I personally think it's advantageous to be forced to think about date calculations differently. I'm not practiced with the interval type described in the Standard but I think I'd like it.
Feb 15 '10 at 12:01 AM
KillerDBA
(comments are locked)
|
|
To get you started - SELECT SYSDATE FROM DUAL - today date SELECT SYSTIMESTAMP FROM DUAL - today timestamp SELECT SYSDATE - 1 FROM DUAL - Yesterday
(comments are locked)
|

