Results 1 to 10 of 10

Thread: how to save time into database when seleced from datetime picker

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    7

    how to save time into database when seleced from datetime picker

    can someone plz tell me how to save time from datetimepicke in to database...i m using vb.net

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,173

    Re: how to save time into database when seleced from datetime picker

    You'll have a textbox. With the icon next to it which launches the datetimepicker. Datetimepicker writes into textbox. In the codebehind, you read what's in the textbox.

  3. #3
    New Member
    Join Date
    Apr 2008
    Posts
    10

    Re: how to save time into database when seleced from datetime picker

    Quote Originally Posted by mendhak
    You'll have a textbox. With the icon next to it which launches the datetimepicker. Datetimepicker writes into textbox. In the codebehind, you read what's in the textbox.
    what icon that u meant? .. i cant find any icon next to text box .. ..

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,173

    Re: how to save time into database when seleced from datetime picker

    Use any image. People usually use a tiny icon of a calendar. Some even use a link. Look at this example

    http://aspnet.4guysfromrolla.com/articles/030202-1.aspx

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    7

    Re: how to save time into database when seleced from datetime picker

    im worlin on window application.....n not on asp.net.....

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,173

    Re: how to save time into database when seleced from datetime picker

    This is the ASP.NET forum. I'll move your thread.

  7. #7
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: how to save time into database when seleced from datetime picker

    Do you have a datetimepicker on your form? if not, add one.

    Code:
        Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
    'add your code here
        End Sub
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  8. #8
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: how to save time into database when seleced from datetime picker

    The DateTime object contains both the date part and the time part. If you just want the time from the Value of your datetimepicker (wich is a datetime object), you would read the TimeOfDay property of that datetime object (which is a TimeSpan). However, you should save the value as datetime and use only the part that you need.

  9. #9

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    7

    Re: how to save time into database when seleced from datetime picker

    can u plz tell me how to retrive only time?im not getting it...plzzzzzzzz

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: how to save time into database when seleced from datetime picker

    Maybe I'm not normal but the extra "z"s don't make me want to help any more than I did. In fact, they make me kind of want to help a little less. They're kind of annoying.

    Anyway, exactly what you should do depends on exactly how you want to use the value. If you want to use the value in code then you'd do as stanav already suggested and get a TimeSpan from the TimeOfDay property of your DateTime:
    vb.net Code:
    1. Dim myDate As Date 'get this value from database.
    2. Dim myTime As TimeSpan = myDate.TimeOfDay
    If you want to display the value to the user then you'd simply format the DateTime as a string:
    vb.net Code:
    1. Dim myDate As Date 'get this value from database.
    2. Dim myTime As String = myDate.ToShortTimeString()
    3.  
    4. MessageBox.Show(myTime)
    5.  
    6. myTime = myDate.ToString("HH:mm")
    7.  
    8. MessageBox.Show(myTime)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width