Wednesday, May 26, 2010

Date Formating like 26th..21st or just 1st

Hi,

A few days before i got a requirement from my client for date formating which is like
"Saturday - 26th June 2010" well it seems to be a small thing but i faced problem when i start changing
date to something like 26th..21st or just 1st...

After some googling i haven't find any good solution or not any inbuild format for this in C#.

So i just create a method which takes the date as a parameter and return the required date format.
and here is this method:

///
/// This method accept the Date and convert it to the format like: Sunday - 3rd October 2010
///

///
///
private string GetFormatedDate(DateTime dateTime)
{

string dateSuffix = (dateTime.Day.ToString().EndsWith("1"))
? ((dateTime.Day.ToString().StartsWith("1") &&
dateTime.Day != 1)
? "th"
: "st")
: (dateTime.Day.ToString().EndsWith("2"))
? (dateTime.Day.ToString().StartsWith("1")
? "th"
: "nd")
: (dateTime.Day.ToString().EndsWith("3"))
? (dateTime.Day.ToString().StartsWith("1")
? "th"
: "rd")
: "th";

return dateTime.ToString("dddd - d~ MMMM yyyy").Replace("~", dateSuffix);

}

In the above example i used Conditional operator which is something like:

CheckCondition ? If_True_Then_This_Value : Else_This_Value;

And at the last line :

return dateTime.ToString("dddd - d~ MMMM yyyy").Replace("~", dateSuffix);

i just suffix a character '~', it can be anything but not the part of any date format and replaced it with the date suffix (ie. th, st, rd or nd).

Hope this will help you guys when you try to do the same.

Cheers.....

Sunday, May 16, 2010

Show and Hide div using Jquery

Hey with just a simple line of code you can show and hide a div...

Before Jquery we write our code something like :

For hiding a div : document.getElementById(id).style.display = 'none';
For Showing a div: document.getElementById(id).style.display = 'block';

and now with the cool feature of JQuery :

For hiding a div : $("#divResult").hide();
For Showing a div: $("#divResult").show();

And also we can play around with this
like

$("#divResult").show(2000);

It will slowly display the div in 2 seconds.....

And for hiding

$("#divResult").hide("slow");

Its hides your div slowly..


Cheers...

Thursday, March 4, 2010

Lambda Expression in .net Part1

Lambda Expression new feature introduce in .net 3.0, is an anonymous method without a name and perform several operation in a few line of codes which is great.

In lambda expression we use the lambda operator => , Known as "goes to".

Here is an example of lambda operator

IList quieueList = list of BookingQueueInfo class;

Now we find all the BookingQueueInfo class which have property QueueEventType as 'ScheduleTimeChange' or as 'ReaccommodationMove'

Here is the code :

List bqiList =
new List(quieueList).FindAll(
q =>
q.QueueEventType == 'ScheduleTimeChange' || q.QueueEventType == 'ReaccommodationMove');

Please post if you have any query for Lambda Expression.

Cheers