How to extract date part ?

Discussion in 'C#' started by kharearch, Sep 6, 2008.

  1. #1
    I am using datetimepicker to accept date from user. It is showing time with date. how can I extract date part from it. I am using following syntax but it is not working.


    DateTimePicker1.CustomFormat = "mm/dd/yy"
    SqlDataAdapter1.SelectCommand.Parameters("@param1").Value = DateTimePicker1.value
    DataSet91.Clear()
    SqlDataAdapter1.Fill(DataSet91)

    can somebody help me to extract date from datetimepicker. Thanks.
     
    kharearch, Sep 6, 2008 IP
  2. yugolancer

    yugolancer Well-Known Member

    Messages:
    320
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #2
    DateTimePicker1.Value.ToShortDateString 'this will return only the date while the time will be nopt displayed
    Code (markup):
     
    yugolancer, Sep 6, 2008 IP
  3. kharearch

    kharearch Member

    Messages:
    82
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    Thanks for reply. It is working now.
     
    kharearch, Sep 6, 2008 IP
  4. gramyla

    gramyla Peon

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Can You tell me the Simple and easy code for taking out the difference between two date in asp.net?
    Thanks in advance.
     
    gramyla, Sep 11, 2008 IP
  5. gramyla

    gramyla Peon

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Can You tell me the Simple and easy code for taking out the difference between two date in asp.net?
    Thanks in advance.
     
    gramyla, Sep 11, 2008 IP
  6. yugolancer

    yugolancer Well-Known Member

    Messages:
    320
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #6
    SELECT <ColumnName> FROM <TableName> WHERE DateColumnName BETWEEN @DateFrom AND @DateTo

    DateFrom and DateTo are params and DateColumnName is DateTime datatype.
     
    yugolancer, Sep 11, 2008 IP
  7. yugolancer

    yugolancer Well-Known Member

    Messages:
    320
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #7
    Otherwise if your Q is not related with the SQL select statement but rather how to measure difference between two dates you can use TimeSpan class for that purpose.

    Dim d1 As Date = CDate("2008-12-01")
    Dim d2 As Date = CDate("2008-12-11")
    Dim t As New TimeSpan
    t = d2.Subtract(d1)

    after that you can simply get any value you want:

    Response.Write(t.Days)
    Response.Write(t.Hours)
    etc.etc.
     
    yugolancer, Sep 11, 2008 IP
  8. gramyla

    gramyla Peon

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks your given code is working.I did not think of this much quick response, thanks again.
     
    gramyla, Sep 16, 2008 IP
  9. yugolancer

    yugolancer Well-Known Member

    Messages:
    320
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #9
    you are welcome but, which reply you found useful .. SQL SELECT statement or the one with using the TimeSpan class?
     
    yugolancer, Sep 22, 2008 IP
  10. AltaMind

    AltaMind Active Member

    Messages:
    331
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    63
    #10
    Thank you, this tips helped me.
     
    AltaMind, Sep 29, 2008 IP