473,651 Members | 2,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datatype

I am using Visual Studio .NET 2003 with SQL Server 2000. I am trying to
insert the date and time into a SQL database by using hour(now). I am
having a hard time trying to figure out which datatype to use in SQL to
store this value. I have tried using datetime, char, nchar, text and
nothing seems to work. Anyone have any ideas? Thanks!

Regards, :)

Christopher Bowen

Jul 23 '05 #1
4 1701
Do you mean that you want to store a time without a date? This isn't
possible in MSSQL, since there is only a single datetime data type.

http://www.aspfaq.com/show.asp?id=2206
http://www.karaszi.com/sqlserver/info_datetime.asp

Simon

Jul 23 '05 #2
Use a DATETIME or SMALLDATETIME column.

INSERT INTO YourTable (dt_col) VALUES (CURRENT_TIMEST AMP)

--
David Portas
SQL Server MVP
--

Jul 23 '05 #3
Christopher,

the function call Hour(Now) will return the current hour, which is an
integer. I would expect this information to be of little use. However,
if you want to store this in an SQL-Server database, then a column of
type tinyint would suffice.

HTH,
Gert-Jan
c_*****@earthli nk.net wrote:

I am using Visual Studio .NET 2003 with SQL Server 2000. I am trying to
insert the date and time into a SQL database by using hour(now). I am
having a hard time trying to figure out which datatype to use in SQL to
store this value. I have tried using datetime, char, nchar, text and
nothing seems to work. Anyone have any ideas? Thanks!

Regards, :)

Christopher Bowen

Jul 23 '05 #4
DH
It would probably be helpful to see your code and it's not 100% clear what
you're trying to do. I'm guessing hour(now) is a .NET function? Does it
simply return the number of the current hour? That would be some sort of
INT, which would be a datatype mismatch with the datatypes you say you've
tried. Your note mentioned "insert the date and time", which wouldn't
simply be the current hour, anyway.

When I want to insert the date and time, I usually use SQL Server's
getdate() function to supply the value. A T-SQL example would be:

create table foo (col1 char(10),col2 datetime)
go
insert foo values ('abc',getdate( ))
go
select * from foo
go

[results]
(1 row(s) affected)

col1 col2
---------- ------------------------------------------------------
abc 2005-02-25 15:16:38.367

(1 row(s) affected)
Use the datetime datatype if you can. In my experience, using character or
numeric types for storing dates and times usually ends up in grief.

By the way, I usually set things up so that SQL Server is responsible for
supplying the time, rather than the application. That way, if the various
workstation's or web server's clocks are a little bit off, the time values
of rows inserted/updated will still be synchronized across your
applications.

<c_*****@earthl ink.net> wrote in message
news:11******** *************@l 41g2000cwc.goog legroups.com...
I am using Visual Studio .NET 2003 with SQL Server 2000. I am trying to
insert the date and time into a SQL database by using hour(now). I am
having a hard time trying to figure out which datatype to use in SQL to
store this value. I have tried using datetime, char, nchar, text and
nothing seems to work. Anyone have any ideas? Thanks!
Regards, :)
Christopher Bowen

Jul 23 '05 #5

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

Similar topics

14
13433
by: Sanjay Minni | last post by:
What is the datatype to be used for Primary Key columns for most optimised access given that - There will be a single column primary key only - The values will only be integers (but as strings) at least 12 digits (characters) long - all positions will be occupied (no leading 0's) - Tables may have upto 1m+ rows
1
4363
by: thepercival | last post by:
Hello, I have a stored procedure and the return data type is number(16) as you can see. but I get it back in the code as a var_numeric and then the precision depends on the value of the returndata. So 0 fits into a short so I have to convert to a short, although I say that my stored procedure has to return a NUMBER(16), thus int. Can anyone tell me how I can determine my return datatype beforehand?
8
1944
by: Eternally | last post by:
Hi folks, I've got a program which has a function which uses templates to accept parameters of any type. Works well, but there's one certain datatype which I want to special case and do an extra thing to. The datatype is a class I made. Is there anyway for me to test a parameters datatype in a template using function?
0
1681
by: SoYouKnowBrig | last post by:
Hi All, I am using Microsoft.ApplicationBlocks.Cache.CacheManager to persist a System.Data.Dataset object. This Dataset object has a DataTable that is created from an existing DataTable using the Clone() method. Before I add the new DataTable to the DataSet, I change the DataType of a DataColumn from System.String to System.Int64. I then add data to the new table and then add it to the DataSet. Then DataSet is then added to the Cache....
10
4018
by: andrewcw | last post by:
I read in a earlier post that I can get the column of a grid to sort by datetime if the column type was set as Date I deserialize my XML and one attribute of the XSD has type as dateTime but upon inspection and behavior in the gri the data type is string. If I preview the dataset with the GUI in VISSTUDIO it shows my datatype to be dateTime .. If I try to rest the datatype I get this erro Additional information: Cannot change DataType...
3
3335
by: Sri | last post by:
In VB, to know the field type of a column stored in a recordset the command I use is If rsQuery.Fields(k).Type = adCurrency Then How will I achieve the same in ASP.net. I could not find a currency data type in asp.net and the type is idenfied as decimal. I have two fields defined in Sql-Server, one is money and other is decimal. In asp.net both are identified as decimal.
1
1176
by: Bryan | last post by:
I have a class called "Prop". I want that class to have a property called "DataType" where the user can select and store a datatype. How can I store a DataType value in a class property. how the code would work in my mind: dim TempProp as new Prop TempProp.DataType = String
4
11961
by: Orchid | last post by:
How can I change a Date datatype to a Number datatype? For example, I want a date 10/31/2006 to show 1031 as Number datatype. But I don't want it becomes 39021. What formula should I use? Thanks for your help!!
0
1210
by: graju80 | last post by:
I am kind of new to Db2... Question: What are the rules that DB2 uses to determine the right datatype for a particular column for on-the-fly SQL generation? For example...
11
1883
by: BD | last post by:
Hi, all. I'm running 8.2 on Windows. This is a development platform for a project whose production environment is running on a mainframe. I believe that the RI compilation process is not quite as robust on Windows as it is in other environments. Here's what I'm finding:
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8795
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7296
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
6157
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
4143
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
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
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
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.