473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

how to insert the exact date in database

Hello to all.
Please help me.
I'm inserting a date into sqlserver 2005 using C#3. my problem is while
insert is successfull my date and time.
It's possible to insert only a date?
--
To be Happy is To be Yourself
Mar 18 '08 #1
4 3410
Hi,

SQLServer 2005 doesn't support only Date, so no, you can only insert a
DateTime.Today to simulate only Date. This will change with SQLServer 2008,
which supports Date, Time and DateTime and a few others as well.

--
Happy Coding!
Morten Wennevik [C# MVP]
"Saimvp" wrote:
Hello to all.
Please help me.
I'm inserting a date into sqlserver 2005 using C#3. my problem is while
insert is successfull my date and time.
It's possible to insert only a date?
--
To be Happy is To be Yourself
Mar 18 '08 #2
"Morten Wennevik [C# MVP]" <Mo************@hotmail.comwrote in message
news:D2**********************************@microsof t.com...
Hi,

SQLServer 2005 doesn't support only Date, so no, you can only insert a
DateTime.Today to simulate only Date. This will change with SQLServer
2008,
which supports Date, Time and DateTime and a few others as well.
Coming soon: more types! I love it!!!!!!!!!

--
Roger Frost
"Logic Is Syntax Independent"
Mar 18 '08 #3
DMG
On Mar 18, 4:21*am, Morten Wennevik [C# MVP]
<MortenWenne...@hotmail.comwrote:
Hi,

SQLServer 2005 doesn't support only Date, so no, you can only insert a
DateTime.Today to simulate only Date. *This will change with SQLServer 2008,
which supports Date, Time and DateTime and a few others as well.

--
Happy Coding!
Morten Wennevik [C# MVP]

"Saimvp" wrote:
Hello to all.
Please help me.
I'm inserting a date into sqlserver 2005 using C#3. my problem is while
insert is successfull my date and time.
It's possible to insert only a date?
--
To be Happy is To be Yourself- Hide quoted text -

- Show quoted text -
For what it is worth here are 2 UDF I have found that will set the
time portion to 12:00:00a and make comparisons work better. The second
one is more cryptic but supposedly faster.

/dg

-- #1
Create function [dbo].[DateOnly](@DateTime DateTime)
-- Returns @DateTime at midnight; i.e., it removes the time portion of
a DateTime value.
returns datetime
as
begin
return dateadd(dd,0, datediff(dd,0,@DateTime))
end
-- #2
CREATE FUNCTION [dbo].[GetDateElement]( @inDateTime as DATETIME )
RETURNS datetime AS
BEGIN
RETURN (select CAST(FLOOR( CAST(@inDateTime AS FLOAT ) )AS
DATETIME))
END
Mar 18 '08 #4
The datetime type in SQL 2005 has both date and Time, but there is nothing to
stop you from inserting only the date part of that and having all the times
be the same (I think it ends up as midnight of that day).
Alternately, you COULD make a varchar which stores the date as a string.
That would kill date comparisons, but would allow you to store just the
date...

Ethan

"Saimvp" wrote:
Hello to all.
Please help me.
I'm inserting a date into sqlserver 2005 using C#3. my problem is while
insert is successfull my date and time.
It's possible to insert only a date?
--
To be Happy is To be Yourself
Mar 18 '08 #5

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

Similar topics

18
by: Robin Lawrie | last post by:
Hi again, another problem! I've moved from an Access database to SQL server and am now having trouble inserting dates and times into seperate fields. I'm using ASP and the code below to get the...
3
by: Bon | last post by:
Dear all How can I convert a datetime in Short Date format to General Date format and then insert into SQL database? I get a date from a field using Request("in_date"), which is in Short...
1
by: clayalphonso | last post by:
Here is the code: <% dim testArray, testArray2 dim Conn, rs dim sSQL, sConnString 'response.write request.form("sel1") 'testArray = split(request.form("sel1"),",") 'for each gidstuff In...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
1
by: shubhra | last post by:
I am taking the date in format DD-MM-YYYY from a popup calendar in the text box in a Jsp. And i need to insert that date in to the database. But my problem is when i am printing the date in webpage...
0
by: radiodes | last post by:
I am very new to SQL/Access, and only use it very limitedly, so apologies ahead of time. I have a website that inserts data into an access database, using the code below. Basically, I've got...
1
by: radiodes | last post by:
I have a website that inserts data into a database, using the code below. Basically, I've got one INSERT INTO statement that inserts one line of data into one database, and and then a php for...
9
by: tommurray | last post by:
Hi I am currently setting up a script so that it inserts information into one table and then follows onto the next few lines and checks to see if the user already has a row in a different table if...
0
BenRatcliffe
by: BenRatcliffe | last post by:
Hi there, I was wondering if anyone could help me. I have a comlpex database with a number of forms that have data entered on them and then saved into the correct table etc. In this instance I am...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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...

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.