473,883 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date Time field in ASP/SQL Server

Can someone please suggest the correct way to store the date & time in SQL
Server? I want to store the date and time a record was created.

What should the field type be in SQL Server?

How can I insert the current date/time into the table using SQL?

I used to have date/time field type in access and use the following code

currTime = Now()

SQL="Insert into <table> (id, recDate) Values (" & sId & ", #" & currTime &
"#)"

conn.execute(SQ L)

Please can someone suggest what the field type I should be using in SQL
Server to store this date and also what should I replace the line
currTime=Now() to?

thanks in advance

Aug 22 '05 #1
2 13616
JP SIngh wrote:
Can someone please suggest the correct way to store the date & time
in SQL Server? I want to store the date and time a record was created.

What should the field type be in SQL Server?
datetime

How can I insert the current date/time into the table using SQL?
You can set its default to GETDATE().

I used to have date/time field type in access and use the following
code

currTime = Now()

SQL="Insert into <table> (id, recDate) Values (" & sId & ", #" &
currTime & "#)"
You could have simply done:

SQL="Insert into <table> (id, recDate) Values (" & sId & ", Now)"
conn.execute(SQ L)

Please can someone suggest what the field type I should be using in
SQL Server to store this date and also what should I replace the line
currTime=Now() to?

thanks in advance


If you set the column's default to GETDATE() then you don't even have to
mention the column in your insert statement.

ALTER TABLE <table> ADD
recDate datetime DEFAULT GETDATE() NOT NULL

SQL="Insert into <table> (id) Values (" & sId & ")"

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Aug 22 '05 #2
> Can someone please suggest the correct way to store the date & time in SQL
Server? I want to store the date and time a record was created.

What should the field type be in SQL Server?
SMALLDATETIME should be sufficient unless you need sub-minute accuracy (if
so, use DATETIME - just realize that sub-minute accuracy doubles your
storage requirement for that column, as well as index size).
How can I insert the current date/time into the table using SQL?
sql = "INSERT table(idColumn, createdDate) SELECT " & sID & ",
CURRENT_TIMESTA MP)"

You don't need to pass the date/time from ASP to SQL Server, since SQL
Server is fully capable of determining the current date and time.
SQL="Insert into <table> (id, recDate) Values (" & sId & ", #" & currTime
&
"#)"


Likewise, in Access, you could say:

SQL="Insert into <table> (id, recDate) Values (" & sId & ", now())"

A
Aug 24 '05 #3

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

Similar topics

6
2213
by: Jerome | last post by:
Hi, I know this is an old problem and I've already tried to look the solution up on the web but I didn't find what I need. So, there's the following situation: I've got an ASP page with a form, containing two fields that poses problems 1. birthday field
1
6199
by: Marius Kaizerman | last post by:
I'm trying to set the current time using now() to a date field on a table which is in sql server. I've tried the following syntax: DoCmd.RunSQL "update openclosepos set closedate= '" & now() & "' where openid= '" & tmpopen & "'" but then I get an error which says that it cannot enter a string value into a date field.
7
31853
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the current date. If not, I'd like to display the error message to ValidationSummary. It seems to make sense to me to use CompareValidator but the problem is put the current date into CompareValidator. So, I created a hidden text field in my aspx. ...
15
18899
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 with it. the output looks like that "01/01/1900 08:59:00" in that case time is
7
4246
by: Jerome | last post by:
Hallo, I know a lot has already been told about date/time fields in a database but still confuses me, specif when dealing with SQLserver(Express). It seems that sqlserver only accepts the date in a "yyyyMMdd" format? (difference between Express and MSDE2000A ?) What is the one and only true way to deal with this problem in VB2005: Local settings are Dutch (Belgium) ; thus date is in "dd/MM/yy" (or perhaps dd/MM/yyyy) and time in...
6
4446
by: yoshitha | last post by:
hi db : sql server 2000 lan : C#.net(ASp.Net) in my database table there are 2 fileds of data type datatime. in field 1 i'm storing date in field 2 i'm storing time.
3
3108
by: divya | last post by:
Hi, I have a table tblbwday with 2 fields Name and Birthday.I have written this script for displaying evryday names of the people on that day. <% set objConn =server.createobject("ADODB.connection") objConn.open "DSN=Photo" Dim sqlSELsite,ObjRSSel sqlSELsite = "SELECT Name FROM tblbwday WHERE B'day ="& date() &" " '
6
12569
by: Luvin lunch | last post by:
Hi, I'm new to access and am very wary of dates as I have limited experience in their manipulation and I know if they're not done properly things can turn ugly quickly. I would like to use a calendar control to allow my users to enter a date but I need them to enter a time as well. It doesn't look like the calendar control will allow times to be entered so I was thinking of having two text boxes. One text box would contain the date...
3
3323
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when the field should only be showing one or the other (date or time). Even on the back end of the database where the column properties are, I have chosen the smallest date/time formats. When the aspx page runs, it shows the date and time (ie:in a...
0
9953
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10768
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10868
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9591
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7984
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7137
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5808
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6009
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4623
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.