Answered by:
Add time to db date

Question
-
User565442435 posted
I have some visual basic the gets the selected date. Here is how I grab the date right now.
Dim stopDate As Date = finishDate.DbSelectedDate
finishDate is a raddatepicker. It gets the date fine i.e. 12/3/2009 but what I need to do is add 23:59:59 to that before I pass it to an sql stored procedure. Does anyone know how I can do that? Thanks,
Thursday, December 3, 2009 2:05 PM
Answers
-
User955742345 posted
two easy ways:
First, make stopDate a DateTime instead of a Date, though this may work either way.
' convert the date to a date string, and concatenate the time value stopDate = CDate(stopDate.ToShortDateString & " 23:59:59") ' or, add a day and subtract a second. stopDate.AddDays(1) stopDate.AddSeconds(-1)
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, December 3, 2009 2:54 PM -
User-1614457691 posted
Man --
Please consider trying something like the following.
CodeInfront...
<%@ page language="VB" autoeventwireup="false" codefile="DateTimeTest1.aspx.vb" inherits="DateTimeTest1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <p> <asp:calendar id="TestCalendar" runat="server" selecteddate="12/03/2009"></asp:calendar> </p> <p> <asp:button id="Test1Button" runat="server" text="Test1" /> </p> <p> <asp:label id="StatusLabel" runat="server"></asp:label> </p> </div> </form> </body> </html>
CodeBehind...
Partial Class DateTimeTest1 Inherits System.Web.UI.Page Protected Sub Test1Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Test1Button.Click Dim myDateTime As DateTime = New DateTime( _ Me.TestCalendar.SelectedDate.Year, _ Me.TestCalendar.SelectedDate.Month, _ Me.TestCalendar.SelectedDate.Day, _ 1, _ 2, _ 3) Me.StatusLabel.Text = myDateTime.ToString("yyyy-MM-dd HH:mm:ss.fffffff tt zzz") End Sub End Class
HTH.
Thank you.
-- Mark Kamoski
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, December 3, 2009 3:02 PM
All replies
-
User955742345 posted
two easy ways:
First, make stopDate a DateTime instead of a Date, though this may work either way.
' convert the date to a date string, and concatenate the time value stopDate = CDate(stopDate.ToShortDateString & " 23:59:59") ' or, add a day and subtract a second. stopDate.AddDays(1) stopDate.AddSeconds(-1)
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, December 3, 2009 2:54 PM -
User-1614457691 posted
Man --
Please consider trying something like the following.
CodeInfront...
<%@ page language="VB" autoeventwireup="false" codefile="DateTimeTest1.aspx.vb" inherits="DateTimeTest1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <p> <asp:calendar id="TestCalendar" runat="server" selecteddate="12/03/2009"></asp:calendar> </p> <p> <asp:button id="Test1Button" runat="server" text="Test1" /> </p> <p> <asp:label id="StatusLabel" runat="server"></asp:label> </p> </div> </form> </body> </html>
CodeBehind...
Partial Class DateTimeTest1 Inherits System.Web.UI.Page Protected Sub Test1Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Test1Button.Click Dim myDateTime As DateTime = New DateTime( _ Me.TestCalendar.SelectedDate.Year, _ Me.TestCalendar.SelectedDate.Month, _ Me.TestCalendar.SelectedDate.Day, _ 1, _ 2, _ 3) Me.StatusLabel.Text = myDateTime.ToString("yyyy-MM-dd HH:mm:ss.fffffff tt zzz") End Sub End Class
HTH.
Thank you.
-- Mark Kamoski
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, December 3, 2009 3:02 PM -
User565442435 posted
Thanks for your replies. I ended up just putting in a date and time picker so it's up to the user now. It's good to have those pieces of information though. Thanks
Thursday, December 3, 2009 3:06 PM