Solved

How getDate() in SP just insert Date?

Posted on 2009-04-03
5
360 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

860 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