Date and Time

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Turner

    Date and Time

    Hi Guys

    I have two DateTime pickers one shows the Date and the other the time, this
    is a requirement of the solution. The problem I have is that when the time
    is saved to the sql database into a datetime field it uses the default date
    which is a problem when I try to sort, what I wanted to know is there a way
    for me to set the date in the time picker to the date in the date picker?

    Any help greatly appreciated.

    Thanks
    Mike



  • Not Aaron

    #2
    Re: Date and Time

    I am going to assume that you HAVE to store the time into a datetime
    field within SQL.

    Before you save the values you can store the datetime value by taking
    the date value of the date picker and putting the time value behind it.
    Then you can through the time value into your db with the correct date
    in front of it. This seems a tad askew though

    hth

    Comment

    • Michael Turner

      #3
      Re: Date and Time

      OK, if you can think of a better way the onyl requirement is that the date
      is in one picker and the time is in another, please let me know I would be
      more than interested, I am taking over someone elses project so I am just
      trying to fix the problems so a different way would suit me fine.

      Mike.

      "Not Aaron" <aaronwhitpan@g mail.com> wrote in message
      news:1106757938 .834645.68230@c 13g2000cwb.goog legroups.com...[color=blue]
      >I am going to assume that you HAVE to store the time into a datetime
      > field within SQL.
      >
      > Before you save the values you can store the datetime value by taking
      > the date value of the date picker and putting the time value behind it.
      > Then you can through the time value into your db with the correct date
      > in front of it. This seems a tad askew though
      >
      > hth
      >
      >[/color]



      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: Date and Time

        MIchael,
        You should be able to set the Value of your Time picker to the Date of the
        Date picker & the Time of the Time picker, when the Date picker's value
        changes.

        Something like:

        Private Sub pickerDate_Valu eChanged(ByVal sender As System.Object, ByVal
        e As System.EventArg s) Handles pickerDate.Valu eChanged
        pickerTime.Valu e =
        pickerDate.Valu e.Date.Add(pick erTime.Value.Ti meOfDay)
        End Sub

        Private Sub pickerTime_Valu eChanged(ByVal sender As System.Object, ByVal
        e As System.EventArg s) Handles pickerTime.Valu eChanged
        Me.labelDateTim e.Text = pickerTime.Valu e.ToString()
        End Sub

        Where pickerDate is a DateTimePicker for the Date value & pickerTime is a
        DateTimePicker for the Time value.

        I would consider encapsulating both controls into a new User Control to
        allow easier reuse & better encapsulation.. .

        Hope this helps
        Jay

        "Michael Turner" <fishing@m-turner.co.uk> wrote in message
        news:utBENU8AFH A.1292@TK2MSFTN GP10.phx.gbl...[color=blue]
        > Hi Guys
        >
        > I have two DateTime pickers one shows the Date and the other the time,
        > this is a requirement of the solution. The problem I have is that when the
        > time is saved to the sql database into a datetime field it uses the
        > default date which is a problem when I try to sort, what I wanted to know
        > is there a way for me to set the date in the time picker to the date in
        > the date picker?
        >
        > Any help greatly appreciated.
        >
        > Thanks
        > Mike
        >
        >[/color]


        Comment

        • Jay B. Harlow [MVP - Outlook]

          #5
          Re: Date and Time

          Michael,
          Do you have a single datetime field on the database or 2 datetime fields?

          I would expect a single datetime field.

          Using the code I posted earlier you can use 2 DateTimePickers , but store
          both values in a single database field.

          Hope this helps
          Jay


          "Michael Turner" <fishing@m-turner.co.uk> wrote in message
          news:%23CHc4d8A FHA.1296@TK2MSF TNGP10.phx.gbl. ..[color=blue]
          > OK, if you can think of a better way the onyl requirement is that the date
          > is in one picker and the time is in another, please let me know I would be
          > more than interested, I am taking over someone elses project so I am just
          > trying to fix the problems so a different way would suit me fine.
          >
          > Mike.
          >
          > "Not Aaron" <aaronwhitpan@g mail.com> wrote in message
          > news:1106757938 .834645.68230@c 13g2000cwb.goog legroups.com...[color=green]
          >>I am going to assume that you HAVE to store the time into a datetime
          >> field within SQL.
          >>
          >> Before you save the values you can store the datetime value by taking
          >> the date value of the date picker and putting the time value behind it.
          >> Then you can through the time value into your db with the correct date
          >> in front of it. This seems a tad askew though
          >>
          >> hth
          >>
          >>[/color]
          >
          >
          >[/color]


          Comment

          Working...