Friday, 19 July 2013

GETUTCDATE() function in sqlserver



--UTC Time
SELECT 'UTC Time' as 'TimeZone','UTC' as 'TimeAbb' ,CONVERT(varchar(20),GETUTCDATE(),113) as 'Current Time'
UNION ALL

--IST Time i.e. India Time=UTC+5:30
SELECT 'India Time' as 'TimeZone','IST' as 'TimeAbb',CONVERT(varchar(20),DATEADD(MI,30,DATEADD(hh,5,GETUTCDATE())),113) as 'Current Time'
UNION ALL

-- Atlantic Time = UTC-4
SELECT 'Atlantic Time' as 'TimeZone','ATS' as 'TimeAbb',CONVERT(varchar(20),DATEADD(hh,-4,GETUTCDATE()),113) as 'Current Time'
UNION ALL

-- Eastern Time = UTC-5
SELECT 'Eastern Time' as 'TimeZone','ETS' as 'TimeAbb',CONVERT(varchar(20),DATEADD(hh,-5,GETUTCDATE()),113) as 'Current Time'
UNION ALL

-- Mountain Time = UTC-6
SELECT 'Mountain Time' as 'TimeZone','MTS' as 'TimeAbb',CONVERT(varchar(20),DATEADD(hh,-6,GETUTCDATE()),113) as 'Current Time'
UNION ALL

-- Pacific Time = UTC-8
SELECT 'Pacific Time' as 'TimeZone','PST' as 'TimeAbb',CONVERT(varchar(20),DATEADD(hh,-8,GETUTCDATE()),113) as 'Current Time'
UNION ALL

-- Alaska Time = UTC-9
SELECT 'Alaska Time' as 'TimeZone','AKST' as 'TimeAbb',CONVERT(varchar(20),DATEADD(hh,-9,GETUTCDATE()),113) as 'Current Time'
UNION ALL

-- Hawai Time = UTC-10
SELECT 'Hawai Time' as 'TimeZone','HST' as 'TimeAbb',CONVERT(varchar(20),DATEADD(hh,-10,GETUTCDATE()),113) as 'Current Time'

Wednesday, 17 July 2013

PdfDocument code in c#

C#:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Drawing.Printing;

using Spire.Pdf;

namespace PdfPrint

{

class Program

{

[STAThread()]

static void Main(string[] args)

{

// Instantiate an object of PdfDocument

PdfDocument doc = new PdfDocument();

string pdfFile = “sample.pdf”;

//load PDF document

doc.LoadFromFile(pdfFile);

//Default printing mode without interaction (default printer to print all pages of the document)

doc.PrintDocument.Print();

//Interaction printing mode(page range,printer,and properties of printing can be freely to selected and set)

PrintDialog dialogPrint = new PrintDialog();

dialogPrint.AllowPrintToFile = true;

dialogPrint.AllowSomePages = true;

dialogPrint.PrinterSettings.MinimumPage = 1;

dialogPrint.PrinterSettings.MaximumPage = doc.Pages.Count;

dialogPrint.PrinterSettings.FromPage = 1;

dialogPrint.PrinterSettings.ToPage = doc.Pages.Count;

if (dialogPrint.ShowDialog() == DialogResult.OK)

{

//the startpage was selected to be printed

doc.PrintFromPage = dialogPrint.PrinterSettings.FromPage;

//the endpage was selected to be printed

doc.PrintToPage = dialogPrint.PrinterSettings.ToPage;

//Choose printer to print pdf document

doc.PrinterName = dialogPrint.PrinterSettings.PrinterName;

PrintDocument printDoc = doc.PrintDocument;

dialogPrint.Document = printDoc;

//Realize printing

printDoc.Print();

}

}

}

}


Tuesday, 16 July 2013

Calculate age on date selection using Javascript

<script type="text/javascript">
        function DateSelectionChanged(e) {
            var today = new Date();
            var dob = e.get_selectedDate();
            var months = (today.getMonth() - dob.getMonth() + (12 * (today.getFullYear() - dob.getFullYear())));
            //alert("Your age: " + Math.round(months / 12));
            var age = Math.round(months / 12);
            if (age < 16) {
                alert("Error Age is less than 16");
            }
        }  
    </script>

<asp:TextBox ID="txtDate" runat="server" />
        <asp:ImageButton runat="server" ID="imgPopup" ImageUrl="~/Images/Calendar.png" />
        <ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" OnClientDateSelectionChanged="DateSelectionChanged"
            TargetControlID="txtDate" PopupButtonID="imgPopup">
        </ajaxToolkit:CalendarExtender>