473,565 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combining a date value with a time value

Hi,

I have a datepicker that show a calender. The user picks a date and the
time component is always 00:00.

I then have a drop down that provides a list of times, (10:00, 11:00 etc),
and I want to combine this with the date value, so that I can store it in a
single field in the database.

How can I combine these two values into one ?

Thanks

Sep 22 '06 #1
6 5627
If it's just times, you can just use the first date object, and call
AddHours to add the number of hours the user selected in the other field.

"Aussie Rules" <Au*********@no spam.nospamwrot e in message
news:uZ******** ******@TK2MSFTN GP02.phx.gbl...
Hi,

I have a datepicker that show a calender. The user picks a date and the
time component is always 00:00.

I then have a drop down that provides a list of times, (10:00, 11:00 etc),
and I want to combine this with the date value, so that I can store it in
a single field in the database.

How can I combine these two values into one ?

Thanks

Sep 22 '06 #2
HI,

Thanks for your reply.

I have tried to apply you suggestion, but have found that the value I am
trying to add to(the time text selected in the drop down) causes a problem
as its a string.

The dropdown contains text values such as (11:00, 11:30).

I get an error as it is trying to convert from a string (11:00) to a type
dbl.

Thanks

"Marina Levit [MVP]" <so*****@nospam .comwrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
If it's just times, you can just use the first date object, and call
AddHours to add the number of hours the user selected in the other field.

"Aussie Rules" <Au*********@no spam.nospamwrot e in message
news:uZ******** ******@TK2MSFTN GP02.phx.gbl...
>Hi,

I have a datepicker that show a calender. The user picks a date and the
time component is always 00:00.

I then have a drop down that provides a list of times, (10:00, 11:00
etc), and I want to combine this with the date value, so that I can store
it in a single field in the database.

How can I combine these two values into one ?

Thanks


Sep 22 '06 #3
Right, well, you didn't specify what you were doing exactly.

Once you get the hours in a numeric value, then you can call AddHours. So
your dropdown should have a text and a value. The text can be "10:00 AM",
but the value would be 10. And you add the value.

"Aussie Rules" <Au*********@no spam.nospamwrot e in message
news:ee******** ******@TK2MSFTN GP02.phx.gbl...
HI,

Thanks for your reply.

I have tried to apply you suggestion, but have found that the value I am
trying to add to(the time text selected in the drop down) causes a problem
as its a string.

The dropdown contains text values such as (11:00, 11:30).

I get an error as it is trying to convert from a string (11:00) to a type
dbl.

Thanks

"Marina Levit [MVP]" <so*****@nospam .comwrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
>If it's just times, you can just use the first date object, and call
AddHours to add the number of hours the user selected in the other field.

"Aussie Rules" <Au*********@no spam.nospamwrot e in message
news:uZ******* *******@TK2MSFT NGP02.phx.gbl.. .
>>Hi,

I have a datepicker that show a calender. The user picks a date and the
time component is always 00:00.

I then have a drop down that provides a list of times, (10:00, 11:00
etc), and I want to combine this with the date value, so that I can
store it in a single field in the database.

How can I combine these two values into one ?

Thanks



Sep 22 '06 #4
Aussie,
In addition to the other comments, you could convert the string to a
TimeSpan then add the timespan to the Date.

Something like:

Private Sub DateTimePicker1 _ValueChanged(B yVal sender As System.Object,
ByVal e As System.EventArg s) Handles DateTimePicker1 .ValueChanged,
ComboBox1.Selec tedIndexChanged
Label1.Text = CStr(Me.DateTim ePicker1.Value. Date +
TimeSpan.Parse( ComboBox1.Selec tedValue))
End Sub
I would consider putting TimeSpan objects in my combo box then simply add
them to the Date...

Something like:

Protected Overrides Sub OnLoad(ByVal e As System.EventArg s)
MyBase.OnLoad(e )
Dim times As New List(Of TimeSpan)
times.Add(New TimeSpan(8, 0, 0))
times.Add(New TimeSpan(8, 30, 0))
times.Add(New TimeSpan(9, 0, 0))
times.Add(New TimeSpan(9, 30, 0))
times.Add(New TimeSpan(10, 0, 0))
times.Add(New TimeSpan(10, 30, 0))
times.Add(New TimeSpan(11, 0, 0))
times.Add(New TimeSpan(11, 30, 0))
Me.ComboBox1.Da taSource = times

End Sub

Private Sub DateTimePicker1 _ValueChanged(B yVal sender As System.Object,
ByVal e As System.EventArg s) Handles DateTimePicker1 .ValueChanged,
ComboBox1.Selec tedIndexChanged
Label1.Text = CStr(Me.DateTim ePicker1.Value. Date +
DirectCast(Comb oBox1.SelectedV alue, TimeSpan))
End Sub

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Aussie Rules" <Au*********@no spam.nospamwrot e in message
news:ee******** ******@TK2MSFTN GP02.phx.gbl...
HI,

Thanks for your reply.

I have tried to apply you suggestion, but have found that the value I am
trying to add to(the time text selected in the drop down) causes a problem
as its a string.

The dropdown contains text values such as (11:00, 11:30).

I get an error as it is trying to convert from a string (11:00) to a type
dbl.

Thanks

"Marina Levit [MVP]" <so*****@nospam .comwrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
>If it's just times, you can just use the first date object, and call
AddHours to add the number of hours the user selected in the other field.

"Aussie Rules" <Au*********@no spam.nospamwrot e in message
news:uZ******* *******@TK2MSFT NGP02.phx.gbl.. .
>>Hi,

I have a datepicker that show a calender. The user picks a date and the
time component is always 00:00.

I then have a drop down that provides a list of times, (10:00, 11:00
etc), and I want to combine this with the date value, so that I can
store it in a single field in the database.

How can I combine these two values into one ?

Thanks


Sep 23 '06 #5
Hi Aussie,

Thanks for the feedback.

Actually, what Marina suggested is storing the actual TimeSpan value in the
values of the item of Combox, instead of storing it in the text
representation of the item. To use this approach, your item that is added
into Combobox.Items collection should a customized object, which contains
at least 2 properties: text representation and value representation. Below
code snippet demonstrate this approach:

Public Class TimeObject
Private _timeobj As TimeSpan
Public ReadOnly Property TimeText() As String
Get
Return _timeobj.ToStri ng()
End Get
End Property

Public Property TimeValue() As TimeSpan
Get
Return _timeobj
End Get
Set(ByVal value As TimeSpan)
_timeobj = value
End Set
End Property

End Class

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim i As Integer

For i = 0 To 5
Dim item As New TimeObject
item.TimeValue = item.TimeValue. Add(New TimeSpan(i, 0, 0))
Me.ComboBox1.It ems.Add(item)
Next
Me.ComboBox1.Di splayMember = "TimeText"
Me.ComboBox1.Va lueMember = "TimeValue"
End Sub

Private Sub ComboBox1_Selec tedIndexChanged (ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
ComboBox1.Selec tedIndexChanged
Dim selected_obj As TimeObject =
CType(Me.ComboB ox1.Items(Me.Co mboBox1.Selecte dIndex), TimeObject)
Dim ts As TimeSpan = selected_obj.Ti meValue
End Sub

Note: while retrieving TimeSpan from database, you should store the time
value in TimeValue property of TimeObject. By using this approach, you may
leverage .Net winform databinding to use the time value.

However, if your design does not want to store time value from database in
a customized TimeObject, you may just add the text representation as the
item to the Combobox items collection. Then you should use TimeSpan.Parse( )
to parse the text representation of the item, like this: Dim ts As TimeSpan
= TimeSpan.Parse( "11:00")

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 25 '06 #6
Jeffrery,
I suggested using a TimeSpan.

Complete with an example where a custom object is not needed!

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
""Jeffrey Tan[MSFT]"" <je***@online.m icrosoft.comwro te in message
news:uT******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hi Aussie,

Thanks for the feedback.

Actually, what Marina suggested is storing the actual TimeSpan value in
the
values of the item of Combox, instead of storing it in the text
representation of the item. To use this approach, your item that is added
into Combobox.Items collection should a customized object, which contains
at least 2 properties: text representation and value representation. Below
code snippet demonstrate this approach:

Public Class TimeObject
Private _timeobj As TimeSpan
Public ReadOnly Property TimeText() As String
Get
Return _timeobj.ToStri ng()
End Get
End Property

Public Property TimeValue() As TimeSpan
Get
Return _timeobj
End Get
Set(ByVal value As TimeSpan)
_timeobj = value
End Set
End Property

End Class

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim i As Integer

For i = 0 To 5
Dim item As New TimeObject
item.TimeValue = item.TimeValue. Add(New TimeSpan(i, 0, 0))
Me.ComboBox1.It ems.Add(item)
Next
Me.ComboBox1.Di splayMember = "TimeText"
Me.ComboBox1.Va lueMember = "TimeValue"
End Sub

Private Sub ComboBox1_Selec tedIndexChanged (ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
ComboBox1.Selec tedIndexChanged
Dim selected_obj As TimeObject =
CType(Me.ComboB ox1.Items(Me.Co mboBox1.Selecte dIndex), TimeObject)
Dim ts As TimeSpan = selected_obj.Ti meValue
End Sub

Note: while retrieving TimeSpan from database, you should store the time
value in TimeValue property of TimeObject. By using this approach, you may
leverage .Net winform databinding to use the time value.

However, if your design does not want to store time value from database in
a customized TimeObject, you may just add the text representation as the
item to the Combobox items collection. Then you should use
TimeSpan.Parse( )
to parse the text representation of the item, like this: Dim ts As
TimeSpan
= TimeSpan.Parse( "11:00")

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no
rights.
Sep 27 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5999
by: Bruce MacDonald | last post by:
I've got a question/request for the SQL gurus. I'm building a model of bandwidth demand in MS Access and want to get aggregated results for demand at each PCP in each time period. The two queries below are used to count the number of households of each Socio-Economic Type (each postcode has been allocated an SE-Type), and use that to count...
4
6278
by: Joe User | last post by:
Hi all....I have a feeling this is going to be one of those twisted query questions, but here it goes anyways.... I want to generate a report that shows the chronology of events (represented by field names). Essentially, I would like to sort the DATE FIELDS for each record in the table by the order of the DATES in those DATE FIELDS. For...
1
1998
by: PATGMorris | last post by:
I've got a Union Query that pulls data from two different tables for chemistry and micro testing. The tables containing very similar data but for reasons not necessary here, cannot be put into one table (differing types of results mainly) However, both have date entry fields for varying time stations from an initial, 2 weeks, 1 month, 2...
3
2388
by: Tom Petersen | last post by:
Brand new to .aspx, and just modifying code. I have this: writer.WriteLine("DTSTART:" & beginDate.ToUniversalTime.ToString("yyyyMMdd\THHmmss\Z") ) I am grabbing the date and time from two fields and just need to combine them into one string for the above to work and I don't know how in .aspx. Here are my fields I am trying to combine,...
15
18872
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract the value in timeonly format by using this command Format(now,"HH:mm:ss") But when I insert it into the Sql Server database, it embadded date value...
12
29435
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as follows: function doDateCheckNow(source, args) { var oDate = document.getElementById(source.controltovalidate); // dd/mm/yyyy
7
3041
by: Frank | last post by:
Hi there, I'm trying to generate a report for an old database and I'm having trouble coming up with an elegant way of going about it. Using cursors and other 'ugly' tools I could get the job done but 1) I don't want the report to take ages to run, 2) I'm not a big fan of cursors! Basically there are tables that track history and each table...
0
2136
by: Hexman | last post by:
Hello All, I'm stumped with this one. I have a Database table ("PROD") and I have set up 2 different opens for it. As you can see I alias two of the columns in the first open. I run OpenST(), load a combo box for date selection. I then close the connection, and remove the dt from the dataset. Now I run OpenST1() and I want to get all...
7
2225
by: isdeveloper | last post by:
Hi All, I have a problem with a table that I want to get nice data out of in a single query. The guys here reckon it can't be done in a single query but I wanted to prove them wrong !! Essentially, I want to get the same column out of the single table, but in one case the column must have a where clause associated with it, and the other...
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.