Thursday, December 26, 2013

Get Date in SQL Function

select day(GETDATE()-10)  Result -- 16
select month(GETDATE())   Result -- 12

select convert(varchar(11), getdate(),100)  Result -- Dec 26 2013
select convert(varchar(11), getdate(),110)  Result -- 12-26-2013
select convert(varchar(11), getdate(),120)  Result -- 2013-12-26

Friday, December 20, 2013

Create Excel File in vb.net

Private Sub cmdexcel_Click()
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet

Dim row As Long
Set xlapp = New Excel.Application
Set xlbook = xlapp.Workbooks.Add
Set xlsheet = xlbook.Worksheets(1)
row = 4
With xlsheet

If optdatewise.Value = True Then
.Cells(1, 1) = "Report of Complaints"
.Cells(2, 1) = "Date : " & Format(date1.Value, "dd/MMM/yyyy") & "  To : " & Format(date2.Value, "dd/MMM/yyyy")
.Rows(2).Font.Bold = True
.Rows(2).Font.Size = 12
Else
.Cells(1, 1) = "Report of Complaints Received Till  '" & Now() & "'"
End If
.Rows(1).Font.Bold = True
.Rows(1).Font.Size = 18

.Cells(3, 1) = "Total Number Of Complaints: "
.Rows(3).Font.Bold = True
.Rows(3).Font.Size = 18

.Columns(1).ColumnWidth = 9
.Columns(2).ColumnWidth = 12
.Columns(3).ColumnWidth = 11
.Columns(4).ColumnWidth = 11
.Columns(5).ColumnWidth = 15
.Columns(6).ColumnWidth = 12
.Columns(7).ColumnWidth = 12
.Columns(8).ColumnWidth = 15
.Columns(9).ColumnWidth = 18
.Columns(10).ColumnWidth = 21

.Rows(row).Font.Bold = True
For i = 0 To grid.Rows - 1
For j = 1 To grid.Cols - 1
If j = 2 And i > 0 Then
.Cells(row, j).Select
 xlapp.ActiveSheet.Hyperlinks.Add Anchor:=xlapp.Selection, Address:=mpath & "\Log Files\" & grid.TextMatrix(i, j) & "\Log.doc", TextToDisplay:=grid.TextMatrix(i, j)
Else
.Cells(row, j) = grid.TextMatrix(i, j)
End If
.Rows.Font.Name = "Centaur"
.Rows(row).WrapText = True
Next
row = row + 1
Next
.Cells(3, 1) = .Cells(3, 1) & row - 5

.Rows(4).AutoFilter
.Rows(5).Activate
xlapp.ActiveWindow.FreezePanes = True
.PageSetup.LeftMargin = 1
.PageSetup.RightMargin = 1
.PageSetup.PrintGridlines = True
.PageSetup.Orientation = xlLandscape
.PageSetup.Zoom = 90
.PageSetup.PrintTitleRows = "$4:$4"
.PageSetup.CenterFooter = "&P of &N"

xlapp.Visible = True
End With
End Sub

Thursday, December 19, 2013

If string was found in the RichTextBox, High Light ,Replace , Skip ..

Dim start As Integer = 0
    Dim indexOfSearchText As Integer = 0
'********************Replace Select Use Replace btn****************
        Dim startindex As Integer = 0

        If txt_Name_Changed.Text.Length > 0 Then
            startindex = FindMyText(txt_Name_Changed.Text.Trim(), start, RichTextBox1.Text.Length)
        End If
        ' If string was found in the RichTextBox, highlight it
        If startindex >= 0 Then
            ' Set the highlight color as red
            RichTextBox1.SelectionBackColor = Color.Plum
            RichTextBox1.SelectedText = lblpname.Text
            ' Find the end index. End Index = number of characters in textbox
            Dim endindex As Integer = txt_Name_Changed.Text.Length
            ' Highlight the search string
            RichTextBox1.Select(startindex, endindex)
            ' mark the start position after the position of last search string
            start = startindex + endindex
        End If

 '********************Skip ^^^ Use SKIP btn**************
        Dim startindex As Integer = 0
        If txt_Name_Changed.Text.Length > 0 Then
            startindex = FindMyText(txt_Name_Changed.Text.Trim(), start, RichTextBox1.Text.Length)
        End If
        If startindex >= 0 Then
            RichTextBox1.SelectionBackColor = Color.White
            Dim endindex As Integer = txt_Name_Changed.Text.Length
            RichTextBox1.Select(startindex, endindex)
            start = startindex + endindex
        End If

**************** Function For Replace And Skip ***********************
 Public Function FindMyText(ByVal txtToSearch As String, ByVal searchStart As Integer, ByVal searchEnd As Integer) As Integer
        ' Unselect the previously searched string
        ' ''If searchStart > 0 AndAlso searchEnd > 0 AndAlso indexOfSearchText >= 0 Then
        ' ''    RichTextBox1.Undo()
        ' ''End If
        ' Set the return value to -1 by default.
        Dim retVal As Integer = -1
        ' A valid starting index should be specified.
        ' if indexOfSearchText = -1, the end of search
        If searchStart >= 0 AndAlso indexOfSearchText >= 0 Then
            ' A valid ending index
            If searchEnd > searchStart OrElse searchEnd = -1 Then
                ' Find the position of search string in RichTextBox
                indexOfSearchText = RichTextBox1.Find(txtToSearch, searchStart, searchEnd, RichTextBoxFinds.None)
                ' Determine whether the text was found in richTextBox1.
                If indexOfSearchText <> -1 Then
                    ' Return the index to the specified search text.
                    retVal = indexOfSearchText
                End If
            End If
        End If
        Return retVal
    End Function

**************write TextChanged  Event on Matching String Txt Box*******************
 Private Sub txt_Name_Changed_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_Name_Changed.TextChanged
        start = 0
        indexOfSearchText = 0
    End Sub

^^^^^^^^^^^^^^^^^^^If string was found in the RichTextBox, Then  High Light .^^^^^^^^^^^^^^^^^^^
 Sub FindTxtInRTB() ' HighLight Search txt In RTF
        Dim srchterm As String = txt_Name_Changed.Text
        Dim index As Int32 = 0
        While index <> -1
            index = RichTextBox1.Find(srchterm, index, RichTextBoxFinds.None)
            If index <> -1 Then

                RichTextBox1.SelectionBackColor = Color.Orange
                index += 1
            End If
        End While
        RichTextBox1.DeselectAll()
    End Sub

Wednesday, December 11, 2013

Find integer from string

 Dim Res As String
Dim str As String = "Sandeep123Kumar"
        For Each c As Char In str
            If IsNumeric(c) Then
                Res = Res & c
            End If
        Next
        MessageBox.Show(Res)

Wednesday, December 4, 2013

Retrieve the ValueMember of the DisplayMember items in checklistbox

Public Sub chklistbox()

        Dim dr As DataTable = objdb.getdata("select district_name,district_id from district_master where state_id='" & "9" & "'")
        If dr.Rows.Count > 0 Then
            CheckedListBox1.DataSource = dr
            CheckedListBox1.DisplayMember = "district_name"
            CheckedListBox1.ValueMember = "district_id"
            CheckedListBox1.Text = Nothing
            dr = Nothing
        Else
            CheckedListBox1.DataSource = Nothing
            CheckedListBox1.Text = Nothing
        End If
    End Sub

when you assign properties value member and display member you can retrieve its value using :

 Label9.Text = CheckBoxList1.SelectedItem.ToString()
        Label8.Text = CheckedListBox1.SelectedValue.ToString()

Monday, December 2, 2013

Select/UnSelect all items in checkboxlist in vb.net

 Private Sub chk_crimeName_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles chk_crimeName.ItemCheck
     

 If e.Index = 0 Then
            If e.NewValue = CheckState.Checked Then
                For i As Integer = 1 To chk_crimeName.Items.Count - 1
                    chk_crimeName.SetItemCheckState(i, CheckState.Checked)
                Next
            ElseIf e.NewValue = CheckState.Unchecked Then
                For i As Integer = 1 To chk_crimeName.Items.Count - 1
                    chk_crimeName.SetItemCheckState(i, CheckState.Unchecked)
                Next
            End If
        End If

    End Sub

Select/UnSelect item of Listbox select On checkboxlist
Dim item1 As String = chk_district.SelectedIndex
            If e.NewValue = CheckState.Checked Then
                ListBox1.SelectedIndex = e.Index
            Else
                ListBox1.SetSelected(e.Index, False)
            End If

Thursday, November 28, 2013

Validate TxtBox For Mobile Number

Private Sub TxtNo_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtNo.KeyPress
        If Asc(e.KeyChar) <> 8 Then
            If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Or TxtNo.Text.Length > 9 Then
                e.Handled = True
            End If
        End If
    End Sub

Tuesday, November 26, 2013

Reset Identity Column Value to 1 in SQL Database


To reset identity column value and start value from “1” during insert new records we need to write query to reset identity column value. Check below Query


DBCC CHECKIDENT (Table_Name, RESEED, New_Reseed_Value)

Table_Name is name of your identity column table

RESEED specifies that the current identity value should be changed.

New_Reseed_Value is the new value to use as the current value of the identity column.   
  

EX: DBCC CHECKIDENT ('UserDetails', RESEED, 0)

Once we run the above query it will reset the identity column in UserDetails table and starts identity column value from “1”



Monday, November 25, 2013

Create Word File in vb.net

First Import NameSpace
******************************************
Imports Microsoft.Office.Interop.Word
Imports Microsoft.Office.Interop
*******************************************
Public Sub createlog()
        Dim comtype1 As String
        Dim wrd As Word.Application
        Dim Doc As Word.Document
        wrd = CreateObject("Word.Application") 'Create Object
        Doc = wrd.Documents.Add()
        comtype1 = "-----BASIC COMPLAINT DETAILS-----"
        Dim strconnection As String = ConfigurationManager.ConnectionStrings("MyDb").ConnectionString
        cn = New SqlConnection(strconnection)
        da = New SqlDataAdapter("select * from call_description order by s_id  desc", cn)
        ds = New DataSet
        da.Fill(ds)
        If ds.Tables(0).Rows.Count - 1 Then
            With Doc.Application
                .Selection.Font.Size = "10"
                .Selection.Font.Name = "Verdana"
                .Selection.Font.Color = &H4696F7  'Orange Color
                .Selection.Font.Bold = True
                .Selection.TypeText(Text:=comtype1 & vbCrLf)
                .Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphJustify
                .Selection.Font.Bold = False
                .Selection.Font.Color = WdColor.wdColorBlack
                .Selection.TypeText(Text:="COMPLAINT REGISTERED THROUGH PHONE " & vbCrLf)
                .Selection.TypeText(Text:="SERIOUSNESS OF COMPLAINT: " & vbCrLf)
                .Selection.TypeText(Text:=ds.Tables(0).Rows(0).Item("call_type") & vbCrLf)
                .Selection.TypeText(Text:="COMPLAINT DATE: ")
                .Selection.TypeText(Text:=ds.Tables(0).Rows(0).Item("date_time") & vbCrLf)
                .Selection.TypeText(Text:="NAME OF VICTIM: ")
                .Selection.TypeText(Text:=ds.Tables(0).Rows(0).Item("VICTIM_NAME") & vbCrLf)
                .Selection.TypeText(Text:="STATE: ")
                .Selection.TypeText(Text:=ds.Tables(0).Rows(0).Item("State") & vbCrLf)
                .Selection.TypeText(Text:="COMPLAINT DETAILS: " & vbCrLf)
                .Selection.TypeText(Text:=Trim(removeextras(CStr(ds.Tables(0).Rows(0).Item("Call_descrip")), vbCrLf)))
            End With
            wrd.ActiveDocument.Protect(WdProtectionType.wdAllowOnlyFormFields, , "admin")
            wrd.ActiveDocument.SaveAs("C:\Documents and Settings\CLIENT4\My Documents\word\Log.doc")
            wrd.ActiveDocument.Close()
            wrd.Quit()
            ' Doc = Nothing
            ' wrd = Nothing
        End If
    End Sub
**************************
 Function removeextras(ByVal sstring As String, ByVal delim As String) As String
        While (sstring Like "*" & delim & delim & "*")
            sstring = Replace(sstring, delim & delim, delim)
        End While
        removeextras = sstring
    End Function

Saturday, November 16, 2013

difference between primary key and unique key and foreign key and composite key in sql

  1. Super Key

    Super key is a set of one or more than one keys that can be used to identify a record uniquely in a table.Example : Primary key, Unique key, Alternate key are subset of Super Keys.
  2. Candidate Key

    A Candidate Key is a set of one or more fields/columns that can identify a record uniquely in a table. There can be multiple Candidate Keys in one table. Each Candidate Key can work as Primary Key.
    Example: In below diagram ID, RollNo and EnrollNo are Candidate Keys since all these three fields can be work as Primary Key.
  3. Primary Key

    Primary key is a set of one or more fields/columns of a table that uniquely identify a record in database table. It can not accept null, duplicate values. Only one Candidate Key can be Primary Key.
  4. Alternate key

    A Alternate key is a key that can be work as a primary key. Basically it is a candidate key that currently is not primary key.
    Example: In below diagram RollNo and EnrollNo becomes Alternate Keys when we define ID as Primary Key.
  5. Composite/Compound Key

    Composite Key is a combination of more than one fields/columns of a table. It can be a Candidate key, Primary key.
  6. Unique Key

    Uniquekey is a set of one or more fields/columns of a table that uniquely identify a record in database table. It is like Primary key but it can accept only one null value and it can not have duplicate values. For more help refer the article Difference between primary key and unique key.
    Foreign Key
  7. Foreign Key is a field in database table that is Primary key in another table. It can accept multiple null, duplicate values. For more help refer the article Difference between primary key and foreign key.
    Example : We can have a DeptID column in the Employee table which is pointing to DeptID column in a department table where it a primary key.
    Defined Keys 
    CREATE TABLE Department 
    (
DeptID int PRIMARY KEY,
Name varchar (50) NOT NULL,
Address varchar (200) NOT NULL, ) 
CREATE TABLE Student 
(
ID int PRIMARY KEY,
RollNo varchar(10) NOT NULL,
Name varchar(50) NOT NULL,
EnrollNo varchar(50) UNIQUE,
Address varchar(200) NOT NULL,
DeptID int FOREIGN KEY REFERENCES Department(DeptID)
)
Note
Practically in database, we have only three types of keys Primary Key, Unique Key and Foreign Key. Other types of keys are only concepts of RDBMS that we need to know.

Thursday, November 14, 2013

What is difference between dll and exe?

Exe
1.These are outbound file.
2.Only one exe file exists per application.
3. .Exe cannot be shared with other applications.

dll
1.These are inbund file .
2.Many dll files may exists in one application.
3.  dll can be shared with other applications.

Monday, October 28, 2013

Find Second Max in SQL

SELECT TOP 1 * From (select Top 2 * from complaint_log ORDER BY s_no DESC)a ORDER BY s_no   

Friday, October 25, 2013

clear ALL textboxes and label

For Each ctrl In Controls
                If TypeOf ctrl Is TextBox Or TypeOf ctrl Is Label Then
                    ctrl.Text = String.Empty
                End If
            Next

How to exploit the SQL Injection Attack

Try ' OR ''=' for user name and password.

Friday, October 18, 2013

Print Character using Asc value

For i = 97 To 122
                k &= "(" & Chr(i) & ")" & vbCrLf
              Label4.Text = k
            Next
            i += 1

Tuesday, September 17, 2013

Format String For Dates

d - Numeric day of the month without a leading zero.
dd - Numeric day of the month with a leading zero.
ddd - Abbreviated name of the day of the week.
dddd - Full name of the day of the week.

f,ff,fff,ffff,fffff,ffffff,fffffff -
Fraction of a second. The more Fs the higher the precision.

h - 12 Hour clock, no leading zero.
hh - 12 Hour clock with leading zero.
H - 24 Hour clock, no leading zero.
HH - 24 Hour clock with leading zero.

m - Minutes with no leading zero.
mm - Minutes with leading zero.

M - Numeric month with no leading zero.
MM - Numeric month with a leading zero.
MMM - Abbreviated name of month.
MMMM - Full month name.

s - Seconds with no leading zero.
ss - Seconds with leading zero.

t - AM/PM but only the first letter.
tt - AM/PM ( a.m. / p.m.)

y - Year with out century and leading zero.
yy - Year with out century, with leading zero.
yyyy - Year with century.

zz - Time zone off set with +/-.

Saturday, September 7, 2013

Difference between DataReader, DataTable and DataSet

DataReader
1. Its an connection oriented, whenever you want fetch the data from database that you need the connection. after fetch the data connection is diconnected. 
2. Its an Read only format, you cann't update records. 

DataSet
1. Its connectionless. whenever you want fetch data from database. its connects indirectly to the database and create a virtual database in local system. then disconnected from database.
2. Its easily read and write data from virtual database.

DataTable
A DataTable object represents a single table in the database. It has a name rows and columns.
There is not much difference between dataset and datatable, dataset is just the collection of datatables.

Friday, August 23, 2013

How do I open SQL Server Management Studio?

For SQL Server 2005, click Start -> Run then type sqlwb

This will open SQL Server Management Studio

Monday, August 12, 2013

VB.NET Generate a random string of numbers and letters

Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn.Click
        Dim s As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
        Dim r As New Random
        Dim sb As New StringBuilder
        For i As Integer = 1 To 4
            Dim idx As Integer = r.Next(0, 35)
            sb.Append(s.Substring(idx, 1))
        Next
        Label2.Text = sb.ToString
    End Sub

Friday, August 2, 2013

Delete files in directory older than 7 days

Dim directory As New IO.DirectoryInfo("C:\Documents and Settings\CLIENT4\My Documents\log\")
        For Each file As IO.FileInfo In directory.GetFiles
            If (Now - file.CreationTime).Days < 7 Then file.Delete()
        Next

Monday, July 29, 2013

Create Folder In VB.net

 Private Sub Ok_Button_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ok_Button.Click
                ' Check if folder exists, if not: create it
        If Not Directory.Exists("D:\" & "SandeepKumarYadav") Then
            Directory.CreateDirectory("D:\" &"SandeepKumarYadav")
            ' Folder created message
            MessageBox.Show("Folder created!", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            ' Folder already exists
            MessageBox.Show("Folder already exists!", "", MessageBoxButtons.OK, MessageBoxIcon.Stop)
        End If
    End Sub

Thursday, July 4, 2013

Opening A URL in vb.net

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        System.Diagnostics.Process.Start("http://www.sandeepsky.blogspot.in")
    End Sub

Thursday, June 6, 2013

DateTime.ToString() Patterns


All the patterns:
0
MM/dd/yyyy
08/22/2006
1
dddd, dd MMMM yyyy
Tuesday, 22 August 2006
2
dddd, dd MMMM yyyy
HH:mm Tuesday, 22 August 2006 06:30
3
dddd, dd MMMM yyyy
hh:mm tt Tuesday, 22 August 2006 06:30 AM
4
dddd, dd MMMM yyyy
H:mm Tuesday, 22 August 2006 6:30
5
dddd, dd MMMM yyyy
h:mm tt Tuesday, 22 August 2006 6:30 AM
6
dddd, dd MMMM yyyy HH:mm:ss
Tuesday, 22 August 2006 06:30:07
7
MM/dd/yyyy HH:mm
08/22/2006 06:30
8
MM/dd/yyyy hh:mm tt
08/22/2006 06:30 AM
9
MM/dd/yyyy H:mm
08/22/2006 6:30
10
MM/dd/yyyy h:mm tt
08/22/2006 6:30 AM
10
MM/dd/yyyy h:mm tt
08/22/2006 6:30 AM
10
MM/dd/yyyy h:mm tt
08/22/2006 6:30 AM
11
MM/dd/yyyy HH:mm:ss
08/22/2006 06:30:07
12
MMMM dd
August 22
13
MMMM dd
August 22
14
yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK
2006-08-22T06:30:07.7199222-04:00
15
yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK
2006-08-22T06:30:07.7199222-04:00
16
ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
Tue, 22 Aug 2006 06:30:07 GMT
17
ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
Tue, 22 Aug 2006 06:30:07 GMT
18
yyyy'-'MM'-'dd'T'HH':'mm':'ss
2006-08-22T06:30:07
19
HH:mm
06:30
20
hh:mm tt
06:30 AM
21
H:mm
6:30
22
h:mm tt
6:30 AM
23
HH:mm:ss
06:30:07
24
yyyy'-'MM'-'dd HH':'mm':'ss'Z'
2006-08-22 06:30:07Z
25
dddd, dd MMMM yyyy HH:mm:ss
Tuesday, 22 August 2006 06:30:07
26
yyyy MMMM
2006 August
27
yyyy MMMM
2006 August
The patterns for DateTime.ToString ( 'd' ) :
0
MM/dd/yyyy
08/22/2006
The patterns for DateTime.ToString ( 'D' ) :
0
dddd, dd MMMM yyyy
Tuesday, 22 August 2006
The patterns for DateTime.ToString ( 'f' ) :
0
dddd, dd MMMM yyyy HH:mm
Tuesday, 22 August 2006 06:30
1
dddd, dd MMMM yyyy hh:mm
tt Tuesday, 22 August 2006 06:30 AM
2
dddd, dd MMMM yyyy H:mm
Tuesday, 22 August 2006 6:30
3
dddd, dd MMMM yyyy h:mm
tt Tuesday, 22 August 2006 6:30 AM
The patterns for DateTime.ToString ( 'F' ) :
0
dddd, dd MMMM yyyy HH:mm:ss
Tuesday, 22 August 2006 06:30:07
The patterns for DateTime.ToString ( 'g' ) :
0
MM/dd/yyyy HH:mm
08/22/2006 06:30
1
MM/dd/yyyy hh:mm
tt 08/22/2006 06:30 AM
2
MM/dd/yyyy H:mm
08/22/2006 6:30
3
MM/dd/yyyy h:mm tt
08/22/2006 6:30 AM
The patterns for DateTime.ToString ( 'G' ) :
0
MM/dd/yyyy HH:mm:ss
08/22/2006 06:30:07
The patterns for DateTime.ToString ( 'm' ) :
0
MMMM dd
August 22
The patterns for DateTime.ToString ( 'r' ) :
0
ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
Tue, 22 Aug 2006 06:30:07 GMT
The patterns for DateTime.ToString ( 's' ) :
0
yyyy'-'MM'-'dd'T'HH':'mm':'ss
2006-08-22T06:30:07
The patterns for DateTime.ToString ( 'u' ) :
0
yyyy'-'MM'-'dd HH':'mm':'ss'Z'
2006-08-22 06:30:07Z
The patterns for DateTime.ToString ( 'U' ) :
0
dddd, dd MMMM yyyy HH:mm:ss
Tuesday, 22 August 2006 06:30:07
The patterns for DateTime.ToString ( 'y' ) :
0
yyyy MMMM 2006 August
Building a custom DateTime.ToString Patterns
The following details the meaning of each pattern character. Note the K and z character.
d
Represents the day of the month as a number from 1 through 31. A single-digit day is formatted without a leading zero
dd
Represents the day of the month as a number from 01 through 31. A single-digit day is formatted with a leading zero
ddd
Represents the abbreviated name of the day of the week (Mon, Tues, Wed etc)
dddd
Represents the full name of the day of the week (Monday, Tuesday etc)
h
12-hour clock hour (e.g. 7)
hh
12-hour clock, with a leading 0 (e.g. 07)
H
24-hour clock hour (e.g. 19)
HH
24-hour clock hour, with a leading 0 (e.g. 19)
m
Minutes
mm
Minutes with a leading zero
M
Month number
MM
Month number with leading zero
MMM
Abbreviated Month Name (e.g. Dec)
MMMM
Full month name (e.g. December)
s
Seconds
ss
Seconds with leading zero
t
Abbreviated AM / PM (e.g. A or P)
tt
AM / PM (e.g. AM or PM
y
Year, no leading zero (e.g. 2001 would be 1)
yy
Year, leadin zero (e.g. 2001 would be 01)
yyy
Year, (e.g. 2001 would be 2001)
yyyy
Year, (e.g. 2001 would be 2001)
K
Represents the time zone information of a date and time value (e.g. +05:00)
z
With DateTime values, represents the signed offset of the local operating system's   time zone from Coordinated Universal Time (UTC), measured in hours. (e.g. +6)
zz
As z but with leadin zero (e.g. +06)
zzz
With DateTime values, represents the signed offset of the local operating system's   time zone from UTC, measured in hours and minutes. (e.g. +06:00)
f
Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value.
ff
Represents the two most significant digits of the seconds fraction; that is, it represents the hundredths of a second in a date and time value.
fff
Represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value.
ffff
Represents the four most significant digits of the seconds fraction; that is, it represents the ten thousandths of a second in a date and time value. While it is possible to display the ten thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.
fffff
Represents the five most significant digits of the seconds fraction; that is, it represents the hundred thousandths of a second in a date and time value. While it is possible to display the hundred thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.
ffffff
Represents the six most significant digits of the seconds fraction; that is, it represents the millionths of a second in a date and time value. While it is possible to display the millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.
fffffff
Represents the seven most significant digits of the seconds fraction; that is, it represents the ten millionths of a second in a date and time value. While it is possible to display the ten millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.
F
Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value. Nothing is displayed if the digit is zero.
:
Represents the time separator defined in the current DateTimeFormatInfo..::.TimeSeparator property. This separator is used to differentiate hours, minutes, and seconds.
/
Represents the date separator defined in the current DateTimeFormatInfo..::.DateSeparator property. This separator is used to differentiate years, months, and days.
"
Represents a quoted string (quotation mark). Displays the literal value of any string   between two quotation marks ("). Your application should precede each quotation mark with an escape character (\).
'
Represents a quoted string (apostrophe). Displays the literal value of any string between two apostrophe (') characters.
%c
Represents the result associated with a c custom format specifier, when the custom date and time format string consists solely of that custom format specifier. That is, to use the d, f, F, h, m, s, t, y, z, H, or M custom format specifier by itself, the application should specify %d, %f, %F, %h, %m, %s, %t, %y, %z, %H, or %M. For more information about using a single format specifier, see Using Single Custom Format Specifiers.
||\c || Represents the escape character, and displays the character "c" as a literal when that character is preceded by the escape character (\). To insert the backslash character itself in the result string, the application should use two escape characters ("\\").

Any other character copies any other character to the result string, without affecting formatting. ||