How to get parts of date like Day Month and Year in VB.Net

saeed3164
 
on Mar 13, 2013 12:32 AM
3811 Views

i acsses Source code function   DatePart and DateName in sql

can or not

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
Amit
 
on Mar 13, 2013 10:53 PM

In vb.net you can use datepart function in a same way you are using in sql like : 

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim currdate As String = DatePart("d", DateTime.Now)
'and so on for others
    End Sub

But in c# you have to have to do some manipulation like  this :

  protected void Page_Load(object sender, EventArgs e)
    {
        DateTime currentdate = DateTime.Now;
        int minutes = currentdate.Minute;
        int seconds = currentdate.Second;
        int day = currentdate.Day;
        int month = currentdate.Month;
        //and so on for others ..................


    }
 
Hope this works for you