Wednesday, 17 July 2013

Calculate total hors between two dates using sql server

declare @WorkingHours int,@TotalHours varchar(50)

Set @WorkingHours = 0
                Select @WorkingHours = DateDiff (second, getdate()-1, getdate())
               
                        SELECT @TotalHours  =  CASE WHEN LEN(H) = 1
                                THEN '0' + h
                                ELSE h END
                                + ':' +
                                CASE WHEN LEN(m) = 1
                                THEN '0' + m
                                ELSE m END
                                + ':' +
                                CASE WHEN LEN(s) = 1
                                THEN '0' + s
                                ELSE s END
                                FROM
                                (
                        select
                          CAST(@WorkingHours / 3600 AS VARCHAR(3)) as [h],
                          CAST(@WorkingHours % 3600 / 60 AS VARCHAR(3)) as [m],
                          CAST(@WorkingHours % 3600 % 60 AS VARCHAR(3))as [s])as x
select @TotalHours


2nd method

DECLARE @articleDT DATETIME;

DECLARE @nowDate DATETIME;




 
-- Time of the ARTICLE created
 
 
SET @articleDT = getdate()-365




 
-- Simulation of NOW datetime

-- (in real world you would probably use GETDATE())
 
 
SET @nowDate = '2015-10-21 06:45:05.703';




 
-- Created 9 days ago.
 
 
SELECT 'Created ' + CAST(DATEDIFF(day, @articleDT, @nowDate) AS NVARCHAR(50)) + ' days ago.';




 
-- Created 1 weeks, 2 days, 3 hours, 25 minutes and 20 seconds ago.
 
 
SELECT 'Created '

+ CAST(DATEDIFF(second, @articleDT, @nowDate) / 60 / 60 / 24 / 7 AS NVARCHAR(50)) + ' weeks, '

+ CAST(DATEDIFF(second, @articleDT, @nowDate) / 60 / 60 / 24 % 7 AS NVARCHAR(50)) + ' days, '

+ CAST(DATEDIFF(second, @articleDT, @nowDate) / 60 / 60 % 24 AS NVARCHAR(50)) + ' hours, '

+ CAST(DATEDIFF(second, @articleDT, @nowDate) / 60 % 60 AS NVARCHAR(50)) + ' minutes and '

+ CAST(DATEDIFF(second, @articleDT, @nowDate) % 60 AS NVARCHAR(50)) + ' seconds ago.';

Monday, 15 July 2013

Rounded corner's for text box

<html>
<head>
<style>
div
{
border:2px solid block;
padding:10px 40px;
background:#dddddd;
width:200px;
border-radius:25px;
}
</style>
</head>
<body>

<div>test text</div>

</body>
</html>

c# list to array and array to list convert

List to Array

List<string> l = new List<string>();
 l.Add("one");
 l.Add("two");
 l.Add("three");
 l.Add("four");
 l.Add("five"); 
 string[] s = l.ToArray(); 
 

Array to List

 string[] s = new string[]
 {
     "one",
     "two",
     "three",
     "four",
     "five"
 };
 
 // Convert with new List constructor.
 List<string> l = new List<string>(s); 
 List<string> l2 = s.ToList();

Friday, 12 July 2013

CSS for string reverse display

ms-filter: "progid:DXImageTransform.Microsoft.BasicImage(rotation=3)";
    -moz-transform: rotate(-90deg);
    -o-transform: rotate(-90deg);
    -webkit-transform: rotate(-90deg);
    position: absolute;
    filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);/* IE6,IE7 */
    /* IE8 */
    /* FF3.5+ */
    /* Opera 10.5 */
    /* Safari 3.1+, Chrome */

Client side Java script example

                String csName = "ChangeDivDir";
                Type csType = this.GetType();

                ClientScriptManager cs = Page.ClientScript;

                if (!cs.IsClientScriptBlockRegistered(csType, csName))
                {

                   
                   System.Text.StringBuilder csText = new System.Text.StringBuilder();
                   csText.Append("<script type=\"text/javascript\">");
                    csText.Append(@"window.alert("Hello")";
                    csText.Append("</script>");
                    cs.RegisterClientScriptBlock(csType, csName, csText.ToString());
                }

Thursday, 11 July 2013

simple StringBuilder example in C#

using System;
using System.Text;

class Program
{
    static void Main()
    {
 StringBuilder sb = new StringBuilder();
 // Append to StringBuilder.
 for (int i = 0; i < 10; i++)
 {
     sb.Append(i).Append(" ");
 }
 Console.WriteLine(sb);
    }

jquery best practices

Wednesday, 10 July 2013

.Net -interview-questions-answers links

http://www.indiabix.com/technical/sql-server-common-questions/
http://www.gointerviews.com/top-50-sql-question-answers/
http://www.gointerviews.com/top-50-asp-net-interview-questions-answers/
http://www.dotnet-tricks.com/Home/Projects

Basic Simple Asp.net + jQuery + JSON example