Solved

How getDate() in SP just insert Date?

Posted on 2009-04-03
5
359 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
ID: 24062125
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
ID: 24062226
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
ID: 24062449
convert(varchar(50), getdate(), 102)
or
convert(varchar(50), getdate(), 111)
0
 
LVL 5

Expert Comment

by:catherinelouise
ID: 24062643
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
ID: 24063270
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Review MS SQL cluster diagram 9 89
Help with SQL joins 9 48
SQL Server Insert where not exists 24 41
How do I subtract date and time within a same column in SQL 4 38
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

810 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