Saturday, November 12, 2011

Uninstall Internet Explorer (IE) 9 from windows 7

  1. Click the Start button Picture of the Start button, type Programs and Features in the search box, and then click View installed updates in the left pane.
  2. Under Uninstall an update, scroll down to the Microsoft Windows section.
  3. Right-click Windows Internet Explorer 9, click Uninstall, and then, when prompted, click Yes.
  4. Click one of the following:
    • Restart now (to finish the process of uninstalling Internet Explorer 9 and restore the previous version of Internet Explorer).
    • Restart later

Monday, October 24, 2011

format-number with 0 in xslt using dot net

I was using the following code in my xslt to format number and then used to apply this xslt on xml in dot net.
<xsl:value-of select="format-number(number,'#.#####')" />
And it was showing result as required but when number value become 0 , it returns the empty as I tried to hard code number value with 0.
<xsl:value-of select="format-number(0,'#.#####')" />
and it was giving outuput 0 but  when I used the same code in simple xslt and simple xml (and linked xslt with xml file in note pad ) and runs this in browser , It gave me the correct result in form of 0.
I was surprised why this is not working in dot net code and working in browser with simple xslt file and xml file without using dot net code.

Then I found a solution regarding dot net as
<xsl:value-of select="format-number(0,'#0.#####')" />
But still I am not be able to understand why this is working in simple browser and not working in dot net code?

Sunday, October 23, 2011

Round issue in c#

Today one of my friend asked me that he has some problems while rounding value to 2 decimal places and he was trying to round "2.145" up to 2 decimal places , he used Math.Round() funciton but it was giving output as 2.14 then I told him to use Math.Round(value, 2, MidpointRounding.AwayFromZero)) and he used it and was very happy that his issue solved .
But later I came to know that there are still issues present with
Math.Round(value, 2, MidpointRounding.AwayFromZero)) as mentioned on msdn at
that it will round 0.145 to 0.14 instead of 0.15 and rounding 2.135 to 2.13 instead of 2.14 becuae of loss of precision.
I found the two solutions for the above problem

Solution 1:
Convert double to decimal
Math.Round((decimal(2.135), 2, MidpointRounding.AwayFromZero) it would show 2.14 and
Math.Round((decimal)0.145, 2, MidpointRounding.AwayFromZero) it would show 0.15

Solution 2:
use Math.Ceiling
System.Math.Ceiling(2.135 * 100) / 100 it would show 2.14
System.Math.Ceiling(0.145 * 100) / 100 it would show 0.15

Thursday, July 21, 2011

DATEDIFF (Transact-SQL) showing wrong values

DATEDIFF (Transact-SQL) showing wrong values

Today I was asked to change a query that was showing the result of last 2 weeks. I have to change the filter criteria of date from last 2 weeks to last 2 months as current query was written like this

where DateDIFF(ww, Employees.JoinDate,getDate())<=2

It was used for to get all employees have join date is less or equal to 2 weeks , so I just change the datepart from week to month as mm and chagne the above line to

AND DateDIFF(mm, Employee.StartDate,getDate())<=2 (I was thinking that it would work to get records for last 2 months ) but when I did some unit testting then I have come to know that it showing the wrong result even those records was also showing which date is more then last 2 months .Then I tried to check the behavior of datediff with different example and reading its documentation form online book (Returns the number of date and time boundaries crossed between two specified dates.) from msdn

The example I tried:

SELECT DATEDIFF(mm,'2011-05-01','2011-07-31')  AS Months




(1 row(s) affected)

And the same start and end date but using datepart day instead of month showing as

SELECT DATEDIFF(dd,'2011-05-01','2011-07-31') AS Days




(1 row(s) affected)

It was showing 91 days but if we execute the query with month it showing 2 months so then I come to know that datediff only cares about boundaries as it was showing 91 days difference because 90 days has been passed but it only shows 2 month difference when using month as datepart because the month boundary is 2 as start date month is 5 and end date month is 7.

Let me show you another example



SET @startdate = '2010-12-19'  December 19 , 2011

SET @enddate = '2010-12-25'   December 25 , 2011


SELECT DATEDIFF(dd,@startdate,@enddate) AS 'day',DATEDIFF(ww,@startdate,@enddate) AS 'Week'

day         Week

----------- -----------

6           0

(1 row(s) affected)

It showing 0  week difference as week boundary did not pass yet and 19 and 25 are in same week of December 2010 that’s why it showing 0 week difference. See the December 2010 month screen shot

But If we changed the start date to 18 december 2011 and end date to 19 December 2011 it would show one week differece as these dates not fall in same week and difference is oen week.



SET @startdate = '2010-12-18'

SET @enddate = '2010-12-19'

SELECT DATEDIFF(dd,@startdate,@enddate) AS 'day',DATEDIFF(ww,@startdate,@enddate) AS 'Week'

day         Week

----------- -----------

1           1

(1 row(s) affected)

See here only 1 day difference and showing 1 week difference however in previous query it was showing only 0 week differce but we have 6 day difference this is because of boundaries that this function considering from datepar (i.e day or week).

Let see another example



SET @startdate = '2010-12-31'

SET @enddate = '2011-01-1'

SELECT DATEDIFF(dd,@startdate,@enddate) AS 'day',DATEDIFF(ww,@startdate,@enddate) AS 'Week',DATEDIFF(mm,@startdate,@enddate) AS 'month',

DATEDIFF(yy,@startdate,@enddate) AS 'year'


day         Week        month       year

----------- ----------- ----------- -----------

1           0           1           1

(1 row(s) affected)

Here result are very interesting as it shows 1 day difference but 0 week difference and more important 1 month and 1 year difference how this happened ?

Same logic as December 31, 2010 and January 01 , 2001 falls in same week so it did list 0 week difference but as month boundary crossed as start date month was December and enddate month is January hence it showed 1 month difference and same is the case for year becuae start date year is 2010 and end date year is 2011 hence it showed 1 year difference.

I hope now its clear the behavior of DateDiff function ,

So what I did for my query that need to show the record for last 2 months I just used like

where Employees.JoinDate >= DATEADD(m, -2, GETDATE())