Monday, July 23, 2012

Get Year, Month, Date From SQL server

If a datetime value stored as int in database like 20120707 the following SQL gives us year as 2012, date as 7, and month as 7

Declare @LocalDateID int
set @LocalDateID=20120707

SELECT DATEPART(year, cast(@LocalDateID as char(8))) [Year],
DATEPART(month, cast(@LocalDateID as char(8))) [Month],
DATEPART(day, cast(@LocalDateID as char(8))) [Date]

Wednesday, July 11, 2012

Researchers and Entrepreneurs- Why, what and how



While reading ASR techniques for Indic languages and HMM, I came across an interesting post and interviews by Prof Raj Reddy ( A famous scientist in AI ) . Few useful questions for researchers and entrepreneurs

Following the wise words in http://seanwise.typepad.com/ the key questions for an entrepreneur include:
  1. Why does anyone (end-user/customer) need this? 
  2. Why you? Why do you have a competitive advantage in brining this product to market? 
  3. Why can't others just copy you? 
  4. Why is it novel, different, better, than anything else? 
  5. How much cash do you want? What are you going to do with it? And what will the results be? 
  6. What's it worth? And why is it worth that much?


Prof. Raj Reddy's Questionnaire for a research proposal/problem is:

  1. What are we trying to do? 
  2. What is the key make-a-difference capability we bring to the table? 
  3. How is it being done today?, How are others approaching the problem? 
  4. What are the limitations of current/proposed approaches? 
  5. What is new in the approach? 
  6. What is the plan for realizing the goal? 
  7. if you succeed who will care? What is the impact? 
  8. How much will it cost and how long will it take? 
  9. What are the mid-term and final exams?

The use of "why" type of questions for entrepreneurs and use of "what" and "how" type of questions for researchers is interesting. And also the final questions for a researcher seems to be the beginning questions for an entrepreneur.

Tuesday, July 10, 2012

Convert yyyymmdd (int ) to Datetime and Datetime to yyyymmdd in C#


string _StartDate = "20120707";
 if (!String.IsNullOrEmpty(StartDate))
      {
            DateTime _ExpiryDate = DateTime.ParseExact(_StartDate, "yyyyMMdd", DateTimeFormatInfo.InvariantInfo);
         }


This will convert 20120707 to 7/7/2012 12:00:00 AM


Now given _ExpiryDate as 7/7/2012 12:00:00 AM, The following will convert from Date to yyyymmdd format


 _ExpiryDate.ToString("yyyyMMdd", System.Globalization.CultureInfo.GetCultureInfo("en-US"));

Thursday, May 10, 2012

Reverse a number


Use it to reverse a given number. Data types are declared as BigIntegers to use this function to find a palindrome given a number.


BigInteger is available in .NET Framework 4.  


You need a reference to  System.Numerics name space to use this datatype.







private BigInteger ReverseNumber(BigInteger n)
        {
            BigInteger left = n;
            BigInteger rev = 0;
            BigInteger r;
            while (left > 0)
            {
                r = left % 10;
                rev = rev * 10 + r;
                left = left / 10;  //left = Math.floor(left / 10); 
            }


            return rev;


        }




If you wish to read a number as a string, the following would be helpful.



 public static string ReverseString(string s)
        {
            char[] arr = s.ToCharArray();
            Array.Reverse(arr);
            return new string(arr);
        }