Solved

How getDate() in SP just insert Date?

Posted on 2009-04-03
5
357 Views
Last Modified: 2012-05-06
Hi

I have a stored proc in MSSQL 2005 to insert datetime datatype by getDate()

However, it inserted 2009-04-04 00:53:05.000

How can it just insert 2009-04-04 to the datetime field in the table?
0
Comment
Question by:techques
  • 2
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
catherinelouise earned 25 total points
Comment Utility
you can use this:
 INSERT dateadd(day, 0, datediff(d,0,getdate()))

Open in new window

0
 
LVL 39

Assisted Solution

by:BrandonGalderisi
BrandonGalderisi earned 25 total points
Comment Utility
As catherine shows, you can use dateadd to strip the time component.  But when you store it as a datetime value, it will store the time (00:00:00.000) as midnight.  SQL Server 20005 doesn't have a DATE date type.  That wasn't added until SQL 2008.
0
 

Expert Comment

by:Budrophious
Comment Utility
convert(varchar(50), getdate(), 102)
or
convert(varchar(50), getdate(), 111)
0
 
LVL 5

Expert Comment

by:catherinelouise
Comment Utility
If the field is a datetime field it will still store the time as 00:00:00:000 with your example Budrophius, as Brandon explains above.  If not, then it will certainly be possible to store just the date.
0
 

Expert Comment

by:Budrophious
Comment Utility
You are correct catherinelouise.  techques, as already mentioned, the date will be stored as a datetime.  To query the date in the format you requested use one of the convert functions I posted.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now