Monday, September 26, 2011

convert date format in sql server

-- remove the time
SELECT CAST(GETDATE() AS date) -- 2009-07-12
-- remove the date
SELECT CAST(GETDATE() AS time) -- 08:46:25.8130000
If you’re not working with SQL Server 2008, you have to improvise.
Cast Date With No Time Using Floor
This example removes the time from the date time by setting it to the beginning of the day.
-- Get the current day with no time
-- 2009-06-29 00:00:00.000
SELECT CAST(FLOOR(CAST(GETDATE() AS float)) AS datetime)
 
-- Get the next day
-- 2009-06-30 00:00:00.000
SELECT CAST(CEILING (CAST(GETDATE() AS float)) AS datetime)
Cast Date with No Time Using Convert
Using convert you can remove the time for display purposes, usually for reporting or the front end.
-- Month first
SELECT CONVERT(varchar(12),GETDATE(), 101)  -- 06/29/2009
SELECT CONVERT(varchar(12),GETDATE(), 110)  -- 06-29-2009
SELECT CONVERT(varchar(12),GETDATE(), 100)  -- Jun 29 2009
SELECT CONVERT(varchar(12),GETDATE(), 107)  -- Jun 29, 2009
 
-- Year first
SELECT CONVERT(varchar(12),GETDATE(), 102)  -- 2009.06.29
SELECT CONVERT(varchar(12),GETDATE(), 111)  -- 2009/06/29
SELECT CONVERT(varchar(12),GETDATE(), 112)  -- 20090629
 
-- Day first
SELECT CONVERT(varchar(12),GETDATE(), 103)  -- 29/06/2009
SELECT CONVERT(varchar(12),GETDATE(), 105)  -- 29-06-2009
SELECT CONVERT(varchar(12),GETDATE(), 104)  -- 29.06.2009
SELECT CONVERT(varchar(12),GETDATE(), 106)  -- 29 Jun 2009
 
-- Time only
SELECT CONVERT(varchar(12),GETDATE(), 108)  -- 07:26:16
SELECT CONVERT(varchar(12),GETDATE(), 114)  -- 07:27:11:203
Roll Your Own Date
To roll your own date format, use the datename function. This is also the only way to get the full month name.
SELECT DATENAME(MONTH, GETDATE())   -- June
SELECT DATENAME(DAY,GETDATE())   -- 29
SELECT DATENAME(YEAR, GETDATE())      -- 2009
 
-- Concatente values
-- June.29.2009
SELECT DATENAME(MONTH, GETDATE()) + '.' + DATENAME(DAY,GETDATE()) + '.' + DATENAME(YEAR, GETDATE())
Here are the rest of the possible datepart intervals:
Date Part Name Interval Values
Year year, yyyy, yy
Quarter quarter, q, qq
Month month, mm, mm
Day of the year dayofyear, dy, y
Day day, dd,. D
Weekday weekday, dw
Week week, wk, ww
Hour hour, hh
Minute minute, mi, n
Second second, ss, s

Friday, September 23, 2011

how to call javascript function on page load


<script language='javascript'>
window.onload = function() {
    debugger;
    if (document.getElementById('hdAdavanceValue').value != null && document.getElementById('hdAdavanceValue').value == "y") {
        document.getElementById('DivAdvance').style.display = 'block';
    }
</script>

Thursday, September 22, 2011

how fetch value from web config


<configuration>
       ....
     <appSettings>
       <add key="dev" value="myusername"/>
       <add key="patel" value="mypassword"/>
     </appSettings>
    ....
</configuration>

string userName = System.Configuration.ConfigurationManager.AppSettings["dev"];
        string password = System.Configuration.ConfigurationManager.AppSettings["patel"];

Wednesday, September 21, 2011

how to split string in javascript

var b = 'I am a JavaScript hacker.'
var temp = new Array();
temp = b.split(' '); or  temp = b.split('.') if you want to split with .;

temp[0] = 'I';
temp[1] = 'am';
temp[2] = 'a';
temp[3] = 'JavaScript';
temp[4] = 'hacker.';

Sunday, September 18, 2011

how to hitting any button on enter

<script type="text/javascript">
function setfocus(evt) {var e = event || evt; // for trans-browser compatibility
var charCode = e.which || e.keyCode;if (charCode == 13) {document.getElementById(
document.getElementById(

}

}
'<%= btnCleartxtSearch.ClientID %>').focus();'<%= btnSearchLocation.ClientID %>').click();return true;</script>

Friday, September 9, 2011

how to set display property of div by javascript


 function MakeVisibal() {

        if (document.getElementById('DivAdvance').style.display == 'none') {
            document.getElementById('DivAdvance').style.display = 'block';
        }
        else {
            document.getElementById('DivAdvance').style.display = 'none';
        }
    }

Friday, September 2, 2011

how to split string sepereted by coma

ALTER FUNCTION [dbo].[Split](@RowData varchar(8000),@SplitOn
)
nvarchar(5) RETURNS @RtnValue table (Id int identity(1,1),Data
)
varchar(8000) AS BEGINDeclare @Cnt int
Set @Cnt = 1While (Charindex(@SplitOn,@RowData)>0)BeginInsert Into @RtnValue (data)
Data
Select = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))
Set @Cnt = @Cnt + 1End
Insert Into @RtnValue (data)Select Data = ltrim(rtrim(@RowData))
END
Return