Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

how to insert the exact date in database

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Saimvp - 18 Mar 2008 08:41 GMT
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?

Signature

To be Happy is To be Yourself

Morten Wennevik [C# MVP] - 18 Mar 2008 10:21 GMT
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.

Signature

Happy Coding!
Morten Wennevik [C# MVP]

> 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?
Roger Frost - 18 Mar 2008 11:14 GMT
> 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!!!!!!!!!

Signature

Roger Frost
"Logic Is Syntax Independent"

DMG - 18 Mar 2008 15:21 GMT
On Mar 18, 4:21 am, Morten Wennevik [C# MVP]
<MortenWenne...@hotmail.com> wrote:
> Hi,
>
[quoted text clipped - 16 lines]
>
> - 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
Ethan Strauss - 18 Mar 2008 15:24 GMT
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

> 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?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.