We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,987 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Date and Time

hi

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

3
Contributors
3
Replies
1 Week
Discussion Span
6 Years Ago
Last Updated
4
Views
infinity4ever
Newbie Poster
22 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

campkev
Posting Pro in Training
484 posts since Jul 2005
Reputation Points: 14
Solved Threads: 19
Skill Endorsements: 0

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)
go

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


Hope this helps
:cool:

Paladine
Master Poster
Team Colleague
824 posts since Feb 2003
Reputation Points: 211
Solved Threads: 27
Skill Endorsements: 0

Thanks alot it works with me now :D

infinity4ever
Newbie Poster
22 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0610 seconds using 2.66MB