ali raza

C#, .Net ,Asp.net and my thoughts

Monthly Archives: March 2009

How to get month date view between two dates in c#

Scenario I got while developing some application. I required month and year view in drop down list between contract starting and ending date. Like “March 2009” “April 2009” until march 2011 so on.

I handled it as follow

DateTime _LoopDate = “1/1/2009”;
string month = string.Empty;
DateTime _EndDate = “1/1/2011”;

while (_LoopDate <= _EndDate)
{
System.Globalization.DateTimeFormatInfo d = new System.Globalization.DateTimeFormatInfo();
month = d.MonthNames[_LoopDate.Month – 1];

drpDate.Items.Add(new ListItem(month + ” ” + _LoopDate.Year.ToString(), _LoopDate.Month.ToString() + ” ” + _LoopDate.Year.ToString()));
//drpdate is dropdownlist
_LoopDate= _LoopDate.AddMonths(1);
}

How to get Month name from current date using c#

Hi i found two methods to do so.

Using Globliziation

System.Globalization.DateTimeFormatInfo d = new System.Globalization.DateTimeFormatInfo();
string month = d.MonthNames[DateTime.Now.Month-1];

Using new date object as follow

string MonthName = GetMonthName(DateTime.Now.Month);
static string GetMonthName(int monthNum)
{
return GetMonthName(monthNum, false);
}
static string GetMonthName(int monthNum, bool abbreviate)
{
if (monthNum < 1 || monthNum > 12)
throw new ArgumentOutOfRangeException(“monthNum”);
DateTime date = new DateTime(1, monthNum, 1);
if (abbreviate)
return date.ToString(“MMM”);
else
return date.ToString(“MMMM”);
}

Chears

how to get year from date in pl sql

pl Sql has function “Extract” this functions works wonders. I used it at many places in my application , i write some samples here

Years

select EXTRACT(YEAR FROM DATE ‘2008-3-17’)YEAR from dual;

Months

select EXTRACT(Month FROM DATE ‘2009-3-17’)Months from dual;

Day

select EXTRACT(day FROM DATE ‘2009-3-17′)Days from dual;

and how i used it my query

select * from tblSales_V where salesId in (select SalesId from OUTLET_SALE_V where outlet_Id =’001198’)
and EXTRACT(YEAR FROM issue_Date) = 2005

chears

Nice Regular expression for text input

i found a use full regular expression vaildating input string, you can use it to filter sql injection attacks while taking input for username, title ect.

^[a-zA-Z]+(([\.\- ][a-zA-Z0-9 ])?[a-zA-Z0-9]*)*$

Aaj Bazaar meiN pabajaulaN chalo

the poem by faiz ahmed faiz constantly comes in my mind. Check it out

 

 

Chashm-e-nam,Jaan-e-Shorida kaafi nahiN
Tohmat-e-Ishq posheeda kaafi nahiN
Aaj Bazaar meiN pabajaulaN chalo
Dast afshaaN chalo, mast-o-raqsaaN chalo
Khaak barsar chalo,khuN badamaaN chalo
raah takta hai sab shehr-e-jaanaN chalo
Aaj bazaar meiN pabajaulaN chalo
haakim-e-sheher bhi majama�e aam bhi
subh-e-nashad bhi,roz-e-nakaam bhi
teer-e-ilzam bhi sange dushnam bhi
pa ba jaulaaN chalo, aaj bazaar meiN
inka damsaaz apne siwa kon hai
shehr-e-jaanaN mein ab basifa kon hai
dast-e-qaatil ke shaayaN raha kon hai
rakht-e-dil bandh lo, dilfigaaro chalo
phir humiN qatal ho aayeN yaaro chalo
Faiz Ahmed Faiz