Pages

Friday, 14 February 2014

Change Date-Time format in ASP .Net, C#

You can change below:
if you want replace "31/12/2005" with "12/31/2005", you can see below code:

DateTime d1 = DateTime.ToDate;
string dd = d1.Day.ToString();
string mm = d1.Month.ToString();
string yyyy = d1.Year.ToString();

string d2 = dd + "/" + mm + "/" + yyyy;

***************************************
another way :
DateTime.Today.ToString("dd-MMM-yyyy");

yourDate.toString("yyyy-MMM-dd hh:mm:ss");

DateTime.ParseExact("04/09/2013 8:09:10 PM","dd/MM/yyyy h:mm:ss tt", CultureInfo.InvariantCulture);

string result = dt.ToString("MM-dd-yyyy", CultureInfo.InvariantCulture);

Tuesday, 27 August 2013

Common regular expression in ASP .Net

Regular expression for mobile number should be start from 7 or 8 or 9
regular expression that should accept Indian mobile numbers. for example...
9788812345
9876512345
7891234567
8122212345
Syntax :
[789][0-9]{9}
Prefixing an optional (+91|0)? could make it more usable.

Regular expression for email , should be taking only numeric domain name like:

abc133@jhjh.dfsd : True
456@jhj.hh : True
8678@656.687 : False
hgh@679.vhhv : False
hgh@jbnj.656 : False

Syntax :
"^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-a-zA-Z]+[.])+[a-zA-Z]{2,6}$"

Wednesday, 21 August 2013

One-liner if statements, how to convert this if-else-statement

Syntax :
return (expression) ? value1 : value2;
If value1 and value2 are actually true and false like in your example, you may as well just

return expression;
or
<result> = <condition> ? <true result> : <false result>;
Example :
string result = 5 > 10 ? "5 is greater than 10." : "5 is not greater than 10.";

Tuesday, 16 July 2013

Auto generated Try, Catch and Finally block in C#

Auto generated Try and Finally
tryf  -> press tab
                    try
                    {

                    }
                    finally
                    {


                    }


Auto generated Try and Catch
tryc ->press tab ->press tab 

                     try
                    {

                    }
                    catch (Exception)
                    {
                        
                        throw;

                    }

Friday, 29 March 2013

How to create duplicate table with new name in SQL Server 2008


How to create duplicate table with new name in SQL Server 2008

or How to copy or backup table

SELECT *
INTO new_table_name 
FROM old_tablename
Or we can select only the columns we want into the new table:
SELECT column_name(s)
INTO new_table_name 
FROM old_tablename
Example :
SELECT *
INTO Employee_Backup
FROM Employee
only columns:
SELECT LastName,FirstName
INTO Employee_Backup
FROM Employee