Get the Monday date of a given week in a given year

A user on Silverlight forum made me to write this post.

Quoting the user question:
"I want to get first and last date of week given by a week number and year"

For example if Week Number is 26 and Year is 2009, then the output must be 29/06/2009.

However I did the first date of given week and year, here is what the logic is:

1) Get the date of the first day of the given year. That is the first date of any year would be Year + "-1-1".
2) Find out the date of the monday of this week. For example, for 2009, the first monday date would be 12-29-2008.
3) Now, when we add (number of weeks * 7) to the very first monday, we get the monday of the given week and given year.

Thats all we have to do.

Here is the sample code:

int iWeek = 26;
int iYear = 2009;
DateTime firstDayOfYear;
DateTime firstMondayOfYear;
DateTime finalDate;
//Step 1
firstDayOfYear = Convert.ToDateTime(iYear.ToString() + "-1-1");
DayOfWeek t = 1 - firstDayOfYear.DayOfWeek + 1;
int intDayOfWeek = (int)firstDayOfYear.DayOfWeek;
//Step 2
firstMondayOfYear = firstDayOfYear.AddDays(1 - intDayOfWeek).Date;
//Stpe 3
finalDate = firstMondayOfYear.AddDays((iWeek) * 7);
 
finalDate will have 6/29/2009.
 
Happy coding  :)

How to write Maths Equation In Silverlight

Hello All,

Inspite of being a PG in Mathematics I always use to think how should we write a maths equation in Silverlight or say superscript for a texblock, So I thought I should blog for it.

Suppose if we want to write an equation something like this:

then how are we going to write this in Silverlight.
Here is a simple way:

I have take a TextBlock in my Xaml Page named tbMathsEquation.
In Code Behind: 
tbMathsEquation.Text  = "(x + 1)";
tbMathsEquation.Text += String.Format(" {0,-3}", '\u00B2');
tbMathsEquation.Text += " = ";
tbMathsEquation.Text += "x";
tbMathsEquation.Text += String.Format(" {0,-3}", '\u00B2');
tbMathsEquation.Text += " + ";
tbMathsEquation.Text += "2x + 1";
 
Here I'm using Unicode Character which might be categorized as an uppercase letter, a lowercase letter, a decimal digit number, a letter number, a connector punctuation, a math symbol, or a currency symbol.
 
Thats all we have to do.
 
Happy Coding :)

Swapping Elements frm one ListBox to another using JavaScript.

Hello All,

Swapping elements from one listbox to another in ASP.NET we always have to postback the page but using Javascript you can do this without doing postback for that page.

You can down the Source Code.

Happy Coding :)

जो बीत गई सो बात गई

Hello All,

I still remember one of my school's Hindi book poem of great poet Harivansh Rai Bachchanji.

Whenever I feel low spirited this poem helps me to rejuvenate me.

"Jo Beet Gayi So Baat Gayi"


जीवन में एक सितारा था
माना वह बेहद प्यारा था
वह डूब गया तो डूब गया
अंबर के आंगन को देखो
कितने इसके तारे टूटे
कितने इसके प्यारे छूटे
जो छूट गए फ़िर कहाँ मिले
पर बोलो टूटे तारों पर
कब अंबर शोक मनाता है
जो बीत गई सो बात गई

जीवन में वह था एक कुसुम
थे उस पर नित्य निछावर तुम
वह सूख गया तो सूख गया
मधुबन की छाती को देखो
सूखी कितनी इसकी कलियाँ
मुरझाईं कितनी वल्लरियाँ
जो मुरझाईं फ़िर कहाँ खिलीं
पर बोलो सूखे फूलों पर
कब मधुबन शोर मचाता है
जो बीत गई सो बात गई

जीवन में मधु का प्याला था
तुमने तन मन दे डाला था
वह टूट गया तो टूट गया
मदिरालय का आंगन देखो
कितने प्याले हिल जाते हैं
गिर मिट्टी में मिल जाते हैं
जो गिरते हैं कब उठते हैं
पर बोलो टूटे प्यालों पर
कब मदिरालय पछताता है
जो बीत गई सो बात गई

मृदु मिट्टी के बने हुए हैं
मधु घट फूटा ही करते हैं
लघु जीवन ले कर आए हैं
प्याले टूटा ही करते हैं
फ़िर भी मदिरालय के अन्दर
मधु के घट हैं,मधु प्याले हैं
जो मादकता के मारे हैं
वे मधु लूटा ही करते हैं
वह कच्चा पीने वाला है
जिसकी ममता घट प्यालों पर
जो सच्चे मधु से जला हुआ
कब रोता है चिल्लाता है
जो बीत गई सो बात गई


Hope it helps everyone of you, whenever you feel low spirited. :)