Sunday 18 December 2011

Get Query String from Javascript

In this tutorial you will se how to get query string values using javascript.
function getQueryString()  
{  
    var vars = [], hash;  
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');  
    for(var i = 0; i < hashes.length; i++)  
    {  
        hash = hashes[i].split('=');  
        vars.push(hash[0]);  
        vars[hash[0]] = hash[1];  
    }  
    return vars;  
}  
Let's suppose we have the following URL
http://www.mysite/home.aspx?id=1&name=test
Calling getQueryString() function would return you the following array:
{  
    "id"    : "1",  
    "name" : "test"  
}
To get the value of parameters you will do this.
var id= getQueryString()["id"];  
var name= getQueryString()["name"];  

Hope this tutorial will help you.

Convert in Uppercae and Lowercase using JavaScript

you can use builtIn javascript .toUpper() and .toLower() functions to convert string into upper or lower case.

var test="This is Test";

var test=test.toUpperCase();   

OutPut:

THIS IS TEST.


var test="This is Test";

var test=test.toLowerCase();   

OutPut:

this is test.

This is very simple and easy.

Different Date Time Conversion in SQL

In this tutorial i will explain different date time conversions avail in SQL.

Below are the list of the different date formats using CONVERT function. As you can that the output of these date formats are of VARCHAR data types, so if you have to compare any dates that are in varchar data type then again you have to convert them in datetime data type.

SELECT convert(varchar, getdate(), 100)  -- mon dd yyyy hh:mm 

Output:-
Sep 16 2011 5:55 PM 

SELECT convert(varchar, getdate(), 101)  --mm/dd/yyyy   

Output:-
09/16/2011 


SELECT convert(varchar, getdate(), 102)  --yyyy.mm.dd 


Output:-
2011.09.16


SELECT convert(varchar, getdate(), 106)  --dd mon yyyy 

Output:-
16 Sep 2011

SELECT convert(varchar, getdate(), 105)  --dd-mm-yyyy

Output:-
16-09-2011

SELECT convert(varchar, getdate(), 107)  --mon dd, yyyy 

Output:-
Sep 16, 2011


SELECT convert(varchar, getdate(), 103)  --dd/mm/yyyy  

Output:-
16/09/2011

SELECT convert(varchar, getdate(), 108)  --hh:mm:ss 

Output:-
17:57:08

Convert.ToString() and .ToString() Functions

The purpose of both Convert.ToString() and .ToString() is same but with a small difference.
The basic difference between them is .ToString() does not handle null value and will throw a NULL reference exception error while Convert.ToString() function handles null value. So always use Convert.ToString().