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.
asked Feb 10, 2010 at 01:26 PM in Default
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).
To get you started -
SELECT SYSDATE FROM DUAL - today date SELECT SYSTIMESTAMP FROM DUAL - today timestamp SELECT SYSDATE - 1 FROM DUAL - Yesterday
answered Feb 10, 2010 at 03:22 PM