i want to insert the current date and time in the sql server database... but i dont know how or what is the formulla exactly..i tried several time but all failed...

basicly what i want is when someone log in the site with the membership the session("Date") will be created, the date and time will be recorded in the sql server database in column date which has a data type of smalldatetime

can anyone help me whith this plz

12 Years
Discussion Span
Last Post by infinity4ever

if you want to have the database match exactly the session date, you will need to pass it in, otherwise, if it can be off by a few seconds(or minutes) then you can simply use the getdate() function in sql.

Post one of your failed attempts and let's see if we can fix it


In the ASP.NET page do something like this

(Assuming your data entry for date is a calendar).. it is the principle / logic here that matters.. not the methods

Session("Date") = Calendar1.Selected + " " + DateAndTime.TimeOfDay


cmd.commandText = "UPDATE tblName " _ 
SET dtm_column = CAST('" & CStr(Session(Date")) & "' AS smalldatetime)
WHERE blah = blah ...

example of this in SQL Server

SELECT CAST('2000-05-08 12:35:29.998' AS smalldatetime)

Result: 2000-05-08 12:35:00

Hope this helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.