|
-
Jul 26th, 2005, 05:08 AM
#1
Thread Starter
New Member
Set time portion of date variable
Can someone tell me how I assign the time element only of a date variable?
The SQL database I have to supply values to has separate fields for the date and time so I want to hold the values in two separate variables prior to calling a stored proc.
Thanx in advance
-
Jul 26th, 2005, 05:58 AM
#2
Re: Set time portion of date variable
Welcome to the forums.
Try something like:
VB Code:
Dim strDate As String
Dim strTime As String
strDate = Format(Now, "mm/dd/yyyy")
strTime = Format(Now, "hh:mm:ss")
-
Jul 26th, 2005, 06:32 AM
#3
Thread Starter
New Member
Re: Set time portion of date variable
Hi Hack,
Thanx for the reply but perhaps I should have been a bit more detailed in my question.
I have two variables of datatype date as I will be supplying two values to the stored proc. Ultimately the data is displayed on a form which uses two datetime picker controls. One control displays the date, the other the time.
The value that will provide both the date and time is held in a single cell of a excel spreadsheet, I am not using the current time that Now() would provide.
Thinking about it I should be able to just set the value of each of the two date variables to the value in the excell cell as that will provide the date and time to both and the controls on the form will display the correct data.
What I would like to know though is how I would manually set the time portion of a date variable as I can't see examples anywhere I have looked.
-
Jul 26th, 2005, 10:34 AM
#4
Re: Set time portion of date variable
There are several ways, using Format is one of them
VB Code:
Dim dteTemp As Date
'set the time only (note date portion is 12/30/1899)
dteTemp = Format(Now, "hh:mm:ss")
dteTemp = TimeSerial(18, 30, 24)
'set the Date & Time
dteTemp = DateSerial(2005, 12, 25) & " " & TimeSerial(10, 30, 33)
dteTemp = Date 'time is 00:00:00
dteTemp = DateAdd("h", 10, dteTemp)
dteTemp = DateAdd("n", 4, dteTemp)
dteTemp = DateAdd("s", 7, dteTemp)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|