Monday, February 6, 2012

Calculating difference of dates in Oracle

November 18, 2009 by · Leave a Comment 

How to calculate difference between two dates in oracle, as subtraction of dates returns numeric value as difference. With some slight changes/enhancements we can track back the subtraction values to some readable date formats: Here are some examples, these can also be amended for user convenience: SQL> SELECT floor(((date1-date2)*24*60*60)/3600) 2 || ‘ HOURS ‘ || [...]

Find week start/end given week number

November 3, 2009 by · Leave a Comment 

I have a table with some dated records. I wanted to do some weekly reports on this data. MySQL has a nifty function dubbed WEEK() which will return a week number. It allows you to break your data into week long intervals very easily. For example, the following query will tell me how many records [...]

How To Calculate the Number of Week Days Between two Dates

November 1, 2009 by · 1 Comment 

If the start date and end date are both week days, then the total number of week days in between is simply: (total difference in days) – (total difference in weeks) * 2 DateDiff(dd, @start, @end) – DateDiff(ww, @start, @end)*2 … since the DateDiff() function with weeks returns the number of week "boundaries" that are [...]